This is an archive of the discontinued LLVM Phabricator instance.

[LLDB][NFC] Fix potential div by 0 "count" can be zero potentially causing div by 0
ClosedPublic

Authored by fixathon on Aug 1 2022, 1:57 PM.

Diff Detail

Event Timeline

fixathon created this revision.Aug 1 2022, 1:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 1:57 PM
fixathon requested review of this revision.Aug 1 2022, 1:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 1:57 PM
fixathon edited the summary of this revision. (Show Details)Aug 1 2022, 1:59 PM
DavidSpickett added a subscriber: DavidSpickett.

Given that testing packet speed by sending no packets seems pointless, I wonder if this should be asserts on the packet counts instead.

If this speed test is something we do as part of connection setup, you'd probably want to know that something went wrong rather than lldb claiming that any speed/packet size/whatever is fine. Then failing to send any real packets later.

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
2483

This could have the same issue if num_packets parameter is 0.

The function has a void return type, with no way to communicate its success/failure status. Perhaps the right thing to do is to mod the function to return error Status, in addition to adding the assert (or some runtime check that works for all build flavors)?

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
2483

This instance of average_per_packet variable is not even being used anywhere in the code, in its local scope. Same for packets_per_second just above it.
These 2 could possibly just be deleted?

I stopped being lazy and went and found where this is used. It's actually a command you can run from the interpreter that prints out the results of the testing.

(lldb) process plugin packet speed-test -c 0
Testing sending 0 packets of various sizes:
<...>
qSpeedTest(send=   1024, recv=   1024) in 0.000000120 s for      0.00 packets/s (0.000000 ms per packet) with standard deviation of 0.000000 ms
Testing receiving 4.0MB of data using varying receive packet sizes:
<...>
qSpeedTest(send=      0, recv=   1024)   4096 packets needed to receive 4.0MB in 0.222097710 s for 18.01 MB/sec for  18442.33 packets/sec (0.054223 ms per packet)

So I think it is legitimate to specify 0 send packets here, if you just want to test receiving. So keep the check you've got and add the same sort of check for the instance above it.

(whether this command should even print anything if you're sending 0 packets, that's a matter for another time)

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
2483

It's used to print to the stream below.

fixathon updated this revision to Diff 449736.Aug 3 2022, 12:12 PM
fixathon edited the summary of this revision. (Show Details)

Address the review comments

clayborg accepted this revision.Aug 3 2022, 3:54 PM
This revision is now accepted and ready to land.Aug 3 2022, 3:54 PM

Thanks for these fixes! I'll fix up the 0 packets sent behaviour when I find some spare time.

Thanks for these fixes! I'll fix up the 0 packets sent behaviour when I find some spare time.

Sounds great. Thanks for the review and suggestions!