diff options
| author | Leandro Pereira <leandro@hardinfo.org> | 2016-07-30 19:59:47 -0300 | 
|---|---|---|
| committer | Leandro Pereira <leandro@hardinfo.org> | 2016-07-30 19:59:47 -0300 | 
| commit | a322f93e99c03d993c3fe73c584dd54b71b38a01 (patch) | |
| tree | 3d2cefd2cdf0d163058c3ed8cdc905cf5113c512 | |
| parent | c4458d0df88018a22c5d929d63c3068b82bef5fc (diff) | |
Fix off-by-one error while scanning benchmarks
| -rw-r--r-- | modules/benchmark.c | 37 | 
1 files changed, 20 insertions, 17 deletions
| diff --git a/modules/benchmark.c b/modules/benchmark.c index 5a252184..19a378fb 100644 --- a/modules/benchmark.c +++ b/modules/benchmark.c @@ -554,11 +554,11 @@ ModuleAbout *hi_module_get_about(void)  static gchar *get_benchmark_results()  { +    gint i;      void (*scan_callback) (gboolean rescan);      sending_benchmark_results = TRUE; -    gint i = G_N_ELEMENTS(entries) - 1;      gchar *machine = module_call_method("devices::getProcessorName");      gchar *machineclock = module_call_method("devices::getProcessorFrequency");      gchar *machineram = module_call_method("devices::getMemoryTotal"); @@ -569,22 +569,25 @@ static gchar *get_benchmark_results()  				    "nbenchmarks=%d\n",  				    machine,  				    machineclock, -				    machineram, i); -    for (; i >= 0; i--) { -	if ((scan_callback = entries[i].scan_callback)) { -	    if (bench_results[i] < 0.0) { -	       /* benchmark was cancelled */ -	       scan_callback(TRUE); -            } else { -  	       scan_callback(FALSE); -            } - -	    result = h_strdup_cprintf("[bench%d]\n" -				      "name=%s\n" -				      "value=%f\n", -				      result, -				      i, entries[i].name, bench_results[i]); -	} +				    machineram, +				    G_N_ELEMENTS(entries) - 1); +    for (i = 0; i < G_N_ELEMENTS(entries); i++) { +        scan_callback = entries[i].scan_callback; +        if (!scan_callback) +            continue; + +        if (bench_results[i] < 0.0) { +           /* benchmark was cancelled */ +           scan_callback(TRUE); +        } else { +           scan_callback(FALSE); +        } + +        result = h_strdup_cprintf("[bench%d]\n" +                                  "name=%s\n" +                                  "value=%f\n", +                                  result, +                                  i, entries[i].name, bench_results[i]);      }      g_free(machine); | 
