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

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

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;`](https://fossil-scm.org/fossil/file?udc=1&ln=1163&ci=trunk&name=src%2Ffileedit.c)

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

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]

> 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."