Libelektra: Warnings about Ignored Return Values

Created on 18 Aug 2017  ·  7Comments  ·  Source: ElektraInitiative/libelektra

Steps to Reproduce

  1. Clone the repository
  2. Build Elektra in Ubuntu 14.04 using the steps provided in .travis.yml

Expected Result

Elektra builds without any warnings

Actual Result

The Travis build reports the following warnings:

src/plugins/crypto/gpg.c: In function ‘libelektra_ELEKTRA_PLUGIN_NAME_C_LTX_elektraPlugingpgCall’:
src/plugins/crypto/gpg.c:787:8: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
    dup (pipe_stdin[0]);
        ^
src/plugins/crypto/gpg.c:793:7: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
   dup (pipe_stdout[1]);
       ^
src/plugins/crypto/gpg.c:798:7: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
   dup (pipe_stderr[1]);
       ^
src/plugins/crypto/gpg.c:818:9: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
   write (pipe_stdin[1], keyValue (msgKey), keyGetValueSize (msgKey));
         ^
[27/777] Building C object src/plugins...ktra-crypto_gcrypt-objects.dir/gpg.c.o
src/plugins/crypto/gpg.c: In function ‘libelektra_crypto_gcrypt_LTX_elektraPlugingpgCall’:
src/plugins/crypto/gpg.c:787:8: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
    dup (pipe_stdin[0]);
        ^
src/plugins/crypto/gpg.c:793:7: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
   dup (pipe_stdout[1]);
       ^
src/plugins/crypto/gpg.c:798:7: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
   dup (pipe_stderr[1]);
       ^
src/plugins/crypto/gpg.c:818:9: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
   write (pipe_stdin[1], keyValue (msgKey), keyGetValueSize (msgKey));
         ^
[33/777] Building C object src/plugins...tra-crypto_openssl-objects.dir/gpg.c.o
src/plugins/crypto/gpg.c: In function ‘libelektra_crypto_openssl_LTX_elektraPlugingpgCall’:
src/plugins/crypto/gpg.c:787:8: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
    dup (pipe_stdin[0]);
        ^
src/plugins/crypto/gpg.c:793:7: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
   dup (pipe_stdout[1]);
       ^
src/plugins/crypto/gpg.c:798:7: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
   dup (pipe_stderr[1]);
       ^
src/plugins/crypto/gpg.c:818:9: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
   write (pipe_stdin[1], keyValue (msgKey), keyGetValueSize (msgKey));
         ^
[34/777] Building C object src/plugins...-csvstorage-objects.dir/csvstorage.c.o
src/plugins/csvstorage/csvstorage.c: In function ‘readNextLine’:
src/plugins/csvstorage/csvstorage.c:250:9: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
   fgets (buffer, len, fp);
         ^
[39/777] Building C object src/plugins...lektra-curlget-objects.dir/curlget.c.o
src/plugins/curlget/curlget.c: In function ‘elektraCurlgetGet’:
src/plugins/curlget/curlget.c:643:8: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
  fread (&buffer, sizeof (char), size, fp);
        ^
src/plugins/curlget/curlget.c: In function ‘elektraCurlgetSet’:
src/plugins/curlget/curlget.c:713:10: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
    fread (&buffer, sizeof (char), size, fp);
          ^
[43/777] Building C object src/plugins.../elektra-fcrypt-objects.dir/fcrypt.c.o
src/plugins/fcrypt/fcrypt.c: In function ‘shredTemporaryFile’:
src/plugins/fcrypt/fcrypt.c:92:9: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
   write (fd, buffer, sizeof (buffer));
         ^
[61/777] Building C object src/plugins...ineendings-objects.dir/lineendings.c.o
src/plugins/lineendings/lineendings.c: In function ‘checkLineEndings’:
src/plugins/lineendings/lineendings.c:55:2: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
  (void)fread (&fc, 1, 1, fp);
  ^
src/plugins/lineendings/lineendings.c:58:3: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
   (void)fread (&sc, 1, 1, fp);
   ^
src/plugins/lineendings/lineendings.c:80:4: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
    (void)fread (&sc, 1, 1, fp);
    ^
[86/777] Building C object src/plugins...solver_fm_b_b-objects.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[88/777] Building C object src/plugins...olver_fm_hb_b-objects.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[89/777] Building C object src/plugins...olver_fm_hp_b-objects.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[92/777] Building C object src/plugins...lver_fm_hpu_b-objects.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[94/777] Building C object src/plugins...olver_fm_pb_b-objects.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[95/777] Building C object src/plugins...olver_fm_ub_x-objects.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[98/777] Building C object src/plugins...ver_fm_uhb_xb-objects.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[99/777] Building C object src/plugins...olver_fm_xb_x-objects.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[102/777] Building C object src/plugin...lver_fm_xhp_x-objects.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[105/777] Building C object src/plugin...olver_fm_xp_x-objects.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[204/777] Building C object src/plugin...iles/elektra-crypto_gcrypt.dir/gpg.c.o
src/plugins/crypto/gpg.c: In function ‘libelektra_crypto_gcrypt_LTX_elektraPlugingpgCall’:
src/plugins/crypto/gpg.c:787:8: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
    dup (pipe_stdin[0]);
        ^
src/plugins/crypto/gpg.c:793:7: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
   dup (pipe_stdout[1]);
       ^
src/plugins/crypto/gpg.c:798:7: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
   dup (pipe_stderr[1]);
       ^
src/plugins/crypto/gpg.c:818:9: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
   write (pipe_stdin[1], keyValue (msgKey), keyGetValueSize (msgKey));
         ^
[209/777] Building C object src/plugin...les/elektra-crypto_openssl.dir/gpg.c.o
src/plugins/crypto/gpg.c: In function ‘libelektra_crypto_openssl_LTX_elektraPlugingpgCall’:
src/plugins/crypto/gpg.c:787:8: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
    dup (pipe_stdin[0]);
        ^
src/plugins/crypto/gpg.c:793:7: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
   dup (pipe_stdout[1]);
       ^
src/plugins/crypto/gpg.c:798:7: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
   dup (pipe_stderr[1]);
       ^
src/plugins/crypto/gpg.c:818:9: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
   write (pipe_stdin[1], keyValue (msgKey), keyGetValueSize (msgKey));
         ^
[211/777] Building C object src/plugin.../elektra-csvstorage.dir/csvstorage.c.o
src/plugins/csvstorage/csvstorage.c: In function ‘readNextLine’:
src/plugins/csvstorage/csvstorage.c:250:9: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
   fgets (buffer, len, fp);
         ^
[220/777] Building C object src/plugin...s/elektra-fcrypt.dir/__/crypto/gpg.c.o
src/plugins/crypto/gpg.c: In function ‘libelektra_ELEKTRA_PLUGIN_NAME_C_LTX_elektraPlugingpgCall’:
src/plugins/crypto/gpg.c:787:8: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
    dup (pipe_stdin[0]);
        ^
src/plugins/crypto/gpg.c:793:7: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
   dup (pipe_stdout[1]);
       ^
src/plugins/crypto/gpg.c:798:7: warning: ignoring return value of ‘dup’, declared with attribute warn_unused_result [-Wunused-result]
   dup (pipe_stderr[1]);
       ^
src/plugins/crypto/gpg.c:818:9: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
   write (pipe_stdin[1], keyValue (msgKey), keyGetValueSize (msgKey));
         ^
[223/777] Building C object src/plugin...akeFiles/elektra-fcrypt.dir/fcrypt.c.o
src/plugins/fcrypt/fcrypt.c: In function ‘shredTemporaryFile’:
src/plugins/fcrypt/fcrypt.c:92:9: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]
   write (fd, buffer, sizeof (buffer));
         ^
[241/777] Building C object src/plugin...lektra-lineendings.dir/lineendings.c.o
src/plugins/lineendings/lineendings.c: In function ‘checkLineEndings’:
src/plugins/lineendings/lineendings.c:55:2: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
  (void)fread (&fc, 1, 1, fp);
  ^
src/plugins/lineendings/lineendings.c:58:3: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
   (void)fread (&sc, 1, 1, fp);
   ^
src/plugins/lineendings/lineendings.c:80:4: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
    (void)fread (&sc, 1, 1, fp);
    ^
[277/777] Building C object src/plugin...ektra-resolver_fm_b_b.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[280/777] Building C object src/plugin...ktra-resolver_fm_hb_b.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[283/777] Building C object src/plugin...ktra-resolver_fm_hp_b.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[286/777] Building C object src/plugin...tra-resolver_fm_hpu_b.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[289/777] Building C object src/plugin...ktra-resolver_fm_pb_b.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[292/777] Building C object src/plugin...ktra-resolver_fm_xb_x.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[293/777] Building C object src/plugin...ktra-resolver_fm_ub_x.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[296/777] Building C object src/plugin...ra-resolver_fm_uhb_xb.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[301/777] Building C object src/plugin...tra-resolver_fm_xhp_x.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[303/777] Building C object src/plugin...ktra-resolver_fm_xp_x.dir/resolver.c.o
src/plugins/resolver/resolver.c: In function ‘elektraSetCommit’:
src/plugins/resolver/resolver.c:984:10: warning: ignoring return value of ‘fchown’, declared with attribute warn_unused_result [-Wunused-result]
   fchown (fd, pk->uid, pk->gid);
          ^
[375/777] Building C object src/plugin...eFiles/elektra-curlget.dir/curlget.c.o
src/plugins/curlget/curlget.c: In function ‘elektraCurlgetGet’:
src/plugins/curlget/curlget.c:643:8: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
  fread (&buffer, sizeof (char), size, fp);
        ^
src/plugins/curlget/curlget.c: In function ‘elektraCurlgetSet’:
src/plugins/curlget/curlget.c:713:10: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
    fread (&buffer, sizeof (char), size, fp);
          ^
[517/777] Building C object src/bindin.../elektraintercept-fs.dir/intercept.c.o
src/bindings/intercept/fs/intercept.c: In function ‘resolvePathname’:
src/bindings/intercept/fs/intercept.c:219:10: warning: ignoring return value of ‘getcwd’, declared with attribute warn_unused_result [-Wunused-result]
   getcwd (cwd, PATH_MAX);
          ^
src/bindings/intercept/fs/intercept.c: In function ‘init’:
src/bindings/intercept/fs/intercept.c:115:9: warning: ignoring return value of ‘getcwd’, declared with attribute warn_unused_result [-Wunused-result]
  getcwd (cwd, PATH_MAX);
         ^
[524/777] Building CXX object src/bind...mark_getenv.dir/benchmark_getenv.cpp.o
src/bindings/intercept/env/benchmarks/benchmark_getenv.cpp: In function ‘void benchmark_getenv()’:
src/bindings/intercept/env/benchmarks/benchmark_getenv.cpp:67:19: warning: ignoring return value of ‘char* getenv(const char*)’, declared with attribute warn_unused_result [-Wunused-result]
   getenv ("HELLO");
                   ^
[592/777] Building C object examples/CMakeFiles/kdbset.dir/kdbset.c.o
examples/kdbset.c: In function ‘showElektraErrorDialog’:
examples/kdbset.c:19:8: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d", &a);
        ^
[617/777] Building C object examples/CMakeFiles/namespace.dir/namespace.c.o
examples/namespace.c: In function ‘main’:
examples/namespace.c:64:8: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
  fgets (s, 100, stdin);
        ^
[632/777] Building C object src/plugin...ta.dir/keytometa/testmod_keytometa.c.o
src/plugins/keytometa/testmod_keytometa.c: In function ‘createMergingKey’:
src/plugins/keytometa/testmod_keytometa.c:34:11: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
  asprintf (&name, "user/convertkey%d", i);
           ^
src/plugins/keytometa/testmod_keytometa.c:35:11: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]
  asprintf (&value, "meta line %d", i);
           ^
src/plugins/keytometa/testmod_keytometa.c:36:11: warning: ignoring return value of ‘asprintf’, declared with attribute warn_unused_result [-Wunused-result]

System Information

  • Elektra Version: master
  • OS: Ubuntu 14.04

Most helpful comment

@sanssecours thank you for reporting! I will have a look at all crypto-related (and fcrypt-related) warnings.

All 7 comments

@sanssecours thank you for reporting! I will have a look at all crypto-related (and fcrypt-related) warnings.

@sanssecours Thank you for the report!

@petermax2 Thanks for doing your part!

I wonder why I do not see the warnings locally. Compiler seems to be 4.8.4, and flags are:

-- C flags are  -std=gnu99  -Wno-deprecated-declarations  -Wstrict-prototypes  -Wno-long-long -pedantic -Wno-variadic-macros -Wall -Wextra -Wno-overlength-strings -Wsign-compare -Wfloat-equal -Wformat-security -Wshadow -Wcomments -Wtrigraphs -Wundef -Wuninitialized -Winit-self -Wmaybe-uninitialized -Wsign-compare -Wfloat-equal -Wformat-security
-- CXX flags are  -std=c++11  -Wno-deprecated-declarations  -Wold-style-cast -Wstrict-null-sentinel -D_GLIBCXX_USE_NANOSLEEP -Wno-missing-field-initializers -Woverloaded-virtual  -Wsign-promo  -Wno-long-long -pedantic -Wno-variadic-macros -Wall -Wextra -Wno-overlength-strings -Wsign-compare -Wfloat-equal -Wformat-security -Wshadow -Wcomments -Wtrigraphs -Wundef -Wuninitialized -Winit-self -Wmaybe-uninitialized

The flags are identical to my system, except it has an additional -Wall at beginning. (Also tried to that locally, does not seem to make a difference.) Does Ubuntu have additional attribute declarations in their header files?

In some of the warnings there is already a (void), which is usually the way to suppress these warnings.

Does Ubuntu have additional attribute declarations in their header files?

I would assume so. Seems like the definitions for the functions above use the function attribute warn_unused_result:

The warn_unused_result attribute causes a warning to be emitted if a caller of the function with this attribute does not use its return value. This is useful for functions where not checking the result is either a security problem or always a bug, such as realloc.

.

In some of the warnings there is already a (void), which is usually the way to suppress these warnings.

I do not think this will work here, since the function annotations specifically state that we should not ignore the return value.

When compiling a Debian package (e.g. with the script scripts/build-debian-package added in 1a8aaaedd9fd198db36d143d2799e0b1380be13e) you also get some unused-result warnings in Debian.

Adding

set (COMMON_FLAGS "${COMMON_FLAGS} -Wunused-result")

in cmake/ElektraCompiling.cmake does not have an effect, it is already default.

I could not reproduce any of the warnings above locally but found another unused return value with clang -Wunused-result in botan_operations.cpp that has not been mentioned above.

It would be interesting to know how to consistently reproduce these warnings.

It would be interesting to know how to consistently reproduce these warnings.

Yes. Seems like we are tied to either use the specific distributions+compilers or look at the output from the build servers.

We need to separate unimportant (benchmarks, test cases, I opened #1664 for them) and important (forgotten) unhandled return values. I 'll fix some of the important ones.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sanssecours picture sanssecours  ·  3Comments

sanssecours picture sanssecours  ·  4Comments

dmoisej picture dmoisej  ·  3Comments

markus2330 picture markus2330  ·  3Comments

e1528532 picture e1528532  ·  4Comments