Divide by zero in 'cping.cpp'
Open
Nobody has claimed this yet.
bug
- Dominant language
- C++
- Stars
- 6.4k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Building and running the sample client bin.X64\cping.exe /i /l localhost, I got a divide by zero exception at this line:
s_rllCycles[E_DCOM] /= s_rllCounts[E_DCOM];
Not sure why. Some issue with incorrect CPU-speed calculation?
But I patched it like this:
--- a/samples/cping/cping.cpp 2022-12-24 09:26:38
+++ b/samples/cping/cping.cpp 2022-12-24 12:55:27
@@ -384,14 +384,19 @@
DumpCycles(E_NET);
#endif
- s_rllCycles[E_DCOM] /= s_rllCounts[E_DCOM];
- s_rllCycles[E_RPC] /= s_rllCounts[E_DCOM];
- s_rllCycles[E_UDP] /= s_rllCounts[E_DCOM];
- s_rllCycles[E_NET] /= s_rllCounts[E_DCOM];
- s_rllTotals[E_DCOM] /= s_rllCounts[E_DCOM];
- s_rllTotals[E_RPC] /= s_rllCounts[E_DCOM];
- s_rllTotals[E_UDP] /= s_rllCounts[E_DCOM];
- s_rllTotals[E_NET] /= s_rllCounts[E_DCOM];
+#define SAFE_DIV(res, div) do { \
+ if (div) \
+ res /= div; \
+ } while (0)
+
+ SAFE_DIV (s_rllCycles[E_DCOM], s_rllCounts[E_DCOM]);
+ SAFE_DIV (s_rllCycles[E_RPC], s_rllCounts[E_DCOM]);
+ SAFE_DIV (s_rllCycles[E_UDP], s_rllCounts[E_DCOM]);
+ SAFE_DIV (s_rllCycles[E_NET], s_rllCounts[E_DCOM]);
+ SAFE_DIV (s_rllTotals[E_DCOM], s_rllCounts[E_DCOM]);
+ SAFE_DIV (s_rllTotals[E_RPC], s_rllCounts[E_DCOM]);
+ SAFE_DIV (s_rllTotals[E_UDP], s_rllCounts[E_DCOM]);
+ SAFE_DIV (s_rllTotals[E_NET], s_rllCounts[E_DCOM]);
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in samples/cping/cping.cpp at the division near line 387, then run bin.X64\cping.exe /i /l localhost to reproduce the exception. Compare the reported SAFE_DIV patch with the surrounding counter calculations and verify that the sample completes without a divide-by-zero exception when s_rllCounts[E_DCOM] is zero.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100