dee

Merge lp:~charlesk/dee/fix-904995 into lp:dee

Proposed by Charles Kerr
Status: Needs review
Proposed branch: lp:~charlesk/dee/fix-904995
Merge into: lp:dee
Diff against target: 45 lines (+22/-13)
1 file modified
tests/test-benchmark.c (+22/-13)
To merge this branch: bzr merge lp:~charlesk/dee/fix-904995
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Francis Ginther Pending
Review via email: mp+210897@code.launchpad.net

Commit message

Fix a potential divide-by-zero error detected by Coverity.

Description of the change

Fix (or, rather, silence) a potential divide-by-zero error detected by Coverity.

This patch fell behind the couch cushions awhile back, but I was cleaning out my branches and found it... good thing it's not an important bug.

To post a comment you must log in.
lp:~charlesk/dee/fix-904995 updated
345. By Charles Kerr

sync with lp:dee

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Unmerged revisions

345. By Charles Kerr

sync with lp:dee

344. By Charles Kerr

silence an improbable div-by-zero coverity warning (bug #904995)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/test-benchmark.c'
2--- tests/test-benchmark.c 2013-02-04 16:07:59 +0000
3+++ tests/test-benchmark.c 2014-03-13 20:34:20 +0000
4@@ -80,19 +80,28 @@
5 if (bench->state == NULL)
6 bench->benchmark_setup (bench);
7 }
8-
9- /* Compute average runtime */
10- avg_runtime = total_runtime / bench->n_runs;
11-
12- /* Compute standard deviation */
13- std_dev = 0;
14- for (i = 0; i < bench->n_runs; i++)
15- {
16- gdouble delta = bench->runs[i].elapsed - avg_runtime;
17- std_dev += delta * delta;
18- }
19- std_dev = sqrt (std_dev / bench->n_runs);
20- coeff_of_var = (std_dev /avg_runtime) * 100;
21+
22+ if (bench->n_runs == 0)
23+ {
24+ avg_runtime = 0;
25+ std_dev = 0;
26+ coeff_of_var = 0;
27+ }
28+ else
29+ {
30+ /* Compute average runtime */
31+ avg_runtime = total_runtime / bench->n_runs;
32+
33+ /* Compute standard deviation */
34+ std_dev = 0;
35+ for (i = 0; i < bench->n_runs; i++)
36+ {
37+ gdouble delta = bench->runs[i].elapsed - avg_runtime;
38+ std_dev += delta * delta;
39+ }
40+ std_dev = sqrt (std_dev / bench->n_runs);
41+ coeff_of_var = (std_dev /avg_runtime) * 100;
42+ }
43
44 /* This is not a very precise way of judging the quality,
45 * but better than rigorous hand waving */

Subscribers

People subscribed via source and target branches

to all changes: