Fossil Forum

fileedit.c: warning: ‘zFileUuid’ may be used uninitialized in this function
Login

fileedit.c: warning: ‘zFileUuid’ may be used uninitialized in this function

fileedit.c: warning: ‘zFileUuid’ may be used uninitialized in this function

(1) By anonymous on 2020-06-03 19:36:40 [source]

Building trunk, getting this warning.

src/fileedit.c: In function ‘fileedit_ajax_setup_filerev’:
src/fileedit.c:1192:31: warning: ‘zFileUuid’ may be used uninitialized in this function [-Wmaybe-uninitialized]
       *frid = fast_uuid_to_rid(zFileUuid);
                               ^

gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4

Looks like initializing it to zero should take care of this, char * zFileUuid = 0;

(2) By Martin Gagnon (mgagnon) on 2020-06-03 20:51:41 in reply to 1 [link] [source]

It seems that this warning doesn't exist when compiling with a more recent version of gcc (or clang).

I tried with the following compiler and I got no warning:

  • gcc-4.9.2 (debian-8)
  • gcc-6.3.0 (debian-9)
  • gcc-7.5.0 (ubuntu-18.04)
  • clang-8 (OpenBSD-6.6)

But with the following older compiler, I get the warning:

  • gcc-4.2.1 (on OpenBSD-6.6 if I force gcc instead of clang-8)
  • gcc-4.7.2 (debian-7)

May be newer compiler are more clever and are able to figure out that with all codepath, the variable is actually never really used uninitialized ?

(3) By Stephan Beal (stephan) on 2020-06-03 20:55:33 in reply to 2 [link] [source]

May be newer compiler are more clever and are able to figure out that with all codepath, the variable is actually never really used uninitialized ?

That's good to hear, but i'll initialize it in the morning if someone hasn't done so by then, "just in case."