Thread (3 messages) 3 messages, 2 authors, 2023-07-05

Re: [PATCH fbtest] Initialize ticks in benchmark()

From: Geert Uytterhoeven <geert@linux-m68k.org>
Date: 2023-07-05 09:23:16

Hi Philipp,

Thanks for your patch!

On Thu, Jun 29, 2023 at 10:28 AM Philipp Zabel [off-list ref] wrote:
Fixes a build error with GCC 13:

  util.c: In function 'benchmark':
  util.c:177:17: error: 'ticks' may be used uninitialized [-Werror=maybe-uninitialized]
  util.c:161:14: note: 'ticks' was declared here
I believe this is a false positive?
(unless your "long" type has only a single bit ;-)

But as this is built with -Werror, I agree it is better to play it safe,
and fix this.
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
quoted hunk ↗ jump to hunk
--- a/util.c
+++ b/util.c
@@ -158,7 +158,7 @@ static uint64_t get_ticks(void)

 double benchmark(void (*func)(unsigned long n, void *data), void *data)
 {
-    uint64_t ticks;
+    uint64_t ticks = 0;
Wouldn't it be better to preinitialize this to 1 instead?
Else an overzealous compiler might detect possible UB in the division
below, and more hell might break loose...

    return 1e6*n/ticks;
     unsigned long n = 1;

     printf("Benchmarking... ");
Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help