diff options
author | David Mitchell <davem@iabyn.com> | 2013-11-24 19:44:41 +0000 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2013-11-24 20:24:25 +0000 |
commit | 04783dc7025287c5d75ab531602c7ec786a1e787 (patch) | |
tree | 049174f15e0cc2c532f5e4b5b072a8fa42350df6 | |
parent | 7616a0c2898b38b86404e7b0afa635e0bf786677 (diff) | |
download | perl-04783dc7025287c5d75ab531602c7ec786a1e787.tar.gz |
fix 'ignoring return value' compiler warnings
Various system functions like write() are marked with the
__warn_unused_result__ attribute, which causes an 'ignoring return value'
warning to be emitted, even if the function call result is cast to (void).
The generic solution seems to be
int rc = write(...);
PERL_UNUSED_VAR(rc);
-rw-r--r-- | dist/threads/lib/threads.pm | 2 | ||||
-rw-r--r-- | dist/threads/threads.xs | 4 | ||||
-rw-r--r-- | doio.c | 11 | ||||
-rw-r--r-- | ext/SDBM_File/sdbm/sdbm.c | 7 | ||||
-rw-r--r-- | mg.c | 48 | ||||
-rw-r--r-- | perlio.c | 7 | ||||
-rw-r--r-- | pp_hot.c | 29 | ||||
-rw-r--r-- | sv.c | 5 | ||||
-rw-r--r-- | thread.h | 4 | ||||
-rw-r--r-- | util.c | 5 |
10 files changed, 83 insertions, 39 deletions
diff --git a/dist/threads/lib/threads.pm b/dist/threads/lib/threads.pm index 5a706f1e5a..2c4c1b5bce 100644 --- a/dist/threads/lib/threads.pm +++ b/dist/threads/lib/threads.pm @@ -5,7 +5,7 @@ use 5.008; use strict; use warnings; -our $VERSION = '1.90'; +our $VERSION = '1.91'; my $XS_VERSION = $VERSION; $VERSION = eval $VERSION; diff --git a/dist/threads/threads.xs b/dist/threads/threads.xs index b3e10f0070..85371655b2 100644 --- a/dist/threads/threads.xs +++ b/dist/threads/threads.xs @@ -713,9 +713,11 @@ S_ithread_create( } PERL_SET_CONTEXT(aTHX); if (!thread) { + int rc; MUTEX_UNLOCK(&MY_POOL.create_destruct_mutex); - (void)PerlLIO_write(PerlIO_fileno(Perl_error_log), + rc = PerlLIO_write(PerlIO_fileno(Perl_error_log), PL_no_mem, strlen(PL_no_mem)); + PERL_UNUSED_VAR(rc); my_exit(1); } Zero(thread, 1, ithread); @@ -879,13 +879,16 @@ Perl_nextargv(pTHX_ GV *gv) (void)PerlLIO_chmod(PL_oldname,PL_filemode); #endif if (fileuid != PL_statbuf.st_uid || filegid != PL_statbuf.st_gid) { + int rc = 0; #ifdef HAS_FCHOWN - (void)fchown(PL_lastfd,fileuid,filegid); + rc = fchown(PL_lastfd,fileuid,filegid); #else #ifdef HAS_CHOWN - (void)PerlLIO_chown(PL_oldname,fileuid,filegid); + rc = PerlLIO_chown(PL_oldname,fileuid,filegid); #endif #endif + /* XXX silently ignore failures */ + PERL_UNUSED_VAR(rc); } } return IoIFP(GvIOp(gv)); @@ -1395,7 +1398,9 @@ S_exec_failed(pTHX_ const char *cmd, int fd, int do_report) Perl_warner(aTHX_ packWARN(WARN_EXEC), "Can't exec \"%s\": %s", cmd, Strerror(e)); if (do_report) { - (void)PerlLIO_write(fd, (void*)&e, sizeof(int)); + int rc = PerlLIO_write(fd, (void*)&e, sizeof(int)); + /* silently ignore failures */ + PERL_UNUSED_VAR(rc); PerlLIO_close(fd); } } diff --git a/ext/SDBM_File/sdbm/sdbm.c b/ext/SDBM_File/sdbm/sdbm.c index f2c213ca2d..f5f893cb18 100644 --- a/ext/SDBM_File/sdbm/sdbm.c +++ b/ext/SDBM_File/sdbm/sdbm.c @@ -301,6 +301,9 @@ makroom(DBM *db, long int hash, int need) char *pag = db->pagbuf; char *New = twin; int smax = SPLTMAX; +#ifdef BADMESS + int rc; +#endif do { /* @@ -375,7 +378,9 @@ makroom(DBM *db, long int hash, int need) * we still cannot fit the key. say goodnight. */ #ifdef BADMESS - (void) write(2, "sdbm: cannot insert after SPLTMAX attempts.\n", 44); + rc = write(2, "sdbm: cannot insert after SPLTMAX attempts.\n", 44); + (void)rc; + #endif return 0; @@ -2774,6 +2774,7 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) break; case '<': { + int rc = 0; const Uid_t new_uid = SvUID(sv); PL_delaymagic_uid = new_uid; if (PL_delaymagic) { @@ -2781,31 +2782,34 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) break; /* don't do magic till later */ } #ifdef HAS_SETRUID - (void)setruid(new_uid); + rc = setruid(new_uid); #else #ifdef HAS_SETREUID - (void)setreuid(new_uid, (Uid_t)-1); + rc = setreuid(new_uid, (Uid_t)-1); #else #ifdef HAS_SETRESUID - (void)setresuid(new_uid, (Uid_t)-1, (Uid_t)-1); + rc = setresuid(new_uid, (Uid_t)-1, (Uid_t)-1); #else if (new_uid == PerlProc_geteuid()) { /* special case $< = $> */ #ifdef PERL_DARWIN /* workaround for Darwin's setuid peculiarity, cf [perl #24122] */ if (new_uid != 0 && PerlProc_getuid() == 0) - (void)PerlProc_setuid(0); + rc = PerlProc_setuid(0); #endif - (void)PerlProc_setuid(new_uid); + rc = PerlProc_setuid(new_uid); } else { Perl_croak(aTHX_ "setruid() not implemented"); } #endif #endif #endif + /* XXX $< currently silently ignores failures */ + PERL_UNUSED_VAR(rc); break; } case '>': { + int rc = 0; const Uid_t new_euid = SvUID(sv); PL_delaymagic_euid = new_euid; if (PL_delaymagic) { @@ -2813,26 +2817,29 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) break; /* don't do magic till later */ } #ifdef HAS_SETEUID - (void)seteuid(new_euid); + rc = seteuid(new_euid); #else #ifdef HAS_SETREUID - (void)setreuid((Uid_t)-1, new_euid); + rc = setreuid((Uid_t)-1, new_euid); #else #ifdef HAS_SETRESUID - (void)setresuid((Uid_t)-1, new_euid, (Uid_t)-1); + rc = setresuid((Uid_t)-1, new_euid, (Uid_t)-1); #else if (new_euid == PerlProc_getuid()) /* special case $> = $< */ - PerlProc_setuid(new_euid); + rc = PerlProc_setuid(new_euid); else { Perl_croak(aTHX_ "seteuid() not implemented"); } #endif #endif #endif + /* XXX $> currently silently ignores failures */ + PERL_UNUSED_VAR(rc); break; } case '(': { + int rc = 0; const Gid_t new_gid = SvGID(sv); PL_delaymagic_gid = new_gid; if (PL_delaymagic) { @@ -2840,26 +2847,29 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) break; /* don't do magic till later */ } #ifdef HAS_SETRGID - (void)setrgid(new_gid); + rc = setrgid(new_gid); #else #ifdef HAS_SETREGID - (void)setregid(new_gid, (Gid_t)-1); + rc = setregid(new_gid, (Gid_t)-1); #else #ifdef HAS_SETRESGID - (void)setresgid(new_gid, (Gid_t)-1, (Gid_t) -1); + rc = setresgid(new_gid, (Gid_t)-1, (Gid_t) -1); #else if (new_gid == PerlProc_getegid()) /* special case $( = $) */ - (void)PerlProc_setgid(new_gid); + rc = PerlProc_setgid(new_gid); else { Perl_croak(aTHX_ "setrgid() not implemented"); } #endif #endif #endif + /* XXX $( currently silently ignores failures */ + PERL_UNUSED_VAR(rc); break; } case ')': { + int rc = 0; Gid_t new_egid; #ifdef HAS_SETGROUPS { @@ -2891,7 +2901,7 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) gary[i] = (Groups_t)Atol(p); } if (i) - (void)setgroups(i, gary); + rc = setgroups(i, gary); Safefree(gary); } #else /* HAS_SETGROUPS */ @@ -2903,22 +2913,24 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) break; /* don't do magic till later */ } #ifdef HAS_SETEGID - (void)setegid(new_egid); + rc = setegid(new_egid); #else #ifdef HAS_SETREGID - (void)setregid((Gid_t)-1, new_egid); + rc = setregid((Gid_t)-1, new_egid); #else #ifdef HAS_SETRESGID - (void)setresgid((Gid_t)-1, new_egid, (Gid_t)-1); + rc = setresgid((Gid_t)-1, new_egid, (Gid_t)-1); #else if (new_egid == PerlProc_getgid()) /* special case $) = $( */ - (void)PerlProc_setgid(new_egid); + rc = PerlProc_setgid(new_egid); else { Perl_croak(aTHX_ "setegid() not implemented"); } #endif #endif #endif + /* XXX $) currently silently ignores failures */ + PERL_UNUSED_VAR(rc); break; } case ':': @@ -457,13 +457,14 @@ PerlIO_debug(const char *fmt, ...) } } if (PL_perlio_debug_fd > 0) { + int rc = 0; #ifdef USE_ITHREADS const char * const s = CopFILE(PL_curcop); /* Use fixed buffer as sv_catpvf etc. needs SVs */ char buffer[1024]; const STRLEN len1 = my_snprintf(buffer, sizeof(buffer), "%.40s:%" IVdf " ", s ? s : "(none)", (IV) CopLINE(PL_curcop)); const STRLEN len2 = my_vsnprintf(buffer + len1, sizeof(buffer) - len1, fmt, ap); - (void)PerlLIO_write(PL_perlio_debug_fd, buffer, len1 + len2); + rc = PerlLIO_write(PL_perlio_debug_fd, buffer, len1 + len2); #else const char *s = CopFILE(PL_curcop); STRLEN len; @@ -472,9 +473,11 @@ PerlIO_debug(const char *fmt, ...) Perl_sv_vcatpvf(aTHX_ sv, fmt, &ap); s = SvPV_const(sv, len); - (void)PerlLIO_write(PL_perlio_debug_fd, s, len); + rc = PerlLIO_write(PL_perlio_debug_fd, s, len); SvREFCNT_dec(sv); #endif + /* silently ignore failures */ + PERL_UNUSED_VAR(rc); } va_end(ap); } @@ -1175,6 +1175,7 @@ PP(pp_aassign) } } if (PL_delaymagic & ~DM_DELAY) { + int rc = 0; /* Will be used to set PL_tainting below */ Uid_t tmp_uid = PerlProc_getuid(); Uid_t tmp_euid = PerlProc_geteuid(); @@ -1183,65 +1184,73 @@ PP(pp_aassign) if (PL_delaymagic & DM_UID) { #ifdef HAS_SETRESUID - (void)setresuid((PL_delaymagic & DM_RUID) ? PL_delaymagic_uid : (Uid_t)-1, + rc = setresuid((PL_delaymagic & DM_RUID) ? PL_delaymagic_uid : (Uid_t)-1, (PL_delaymagic & DM_EUID) ? PL_delaymagic_euid : (Uid_t)-1, (Uid_t)-1); #else # ifdef HAS_SETREUID - (void)setreuid((PL_delaymagic & DM_RUID) ? PL_delaymagic_uid : (Uid_t)-1, + rc = setreuid((PL_delaymagic & DM_RUID) ? PL_delaymagic_uid : (Uid_t)-1, (PL_delaymagic & DM_EUID) ? PL_delaymagic_euid : (Uid_t)-1); # else # ifdef HAS_SETRUID if ((PL_delaymagic & DM_UID) == DM_RUID) { - (void)setruid(PL_delaymagic_uid); + rc = setruid(PL_delaymagic_uid); PL_delaymagic &= ~DM_RUID; } # endif /* HAS_SETRUID */ # ifdef HAS_SETEUID if ((PL_delaymagic & DM_UID) == DM_EUID) { - (void)seteuid(PL_delaymagic_euid); + rc = seteuid(PL_delaymagic_euid); PL_delaymagic &= ~DM_EUID; } # endif /* HAS_SETEUID */ if (PL_delaymagic & DM_UID) { if (PL_delaymagic_uid != PL_delaymagic_euid) DIE(aTHX_ "No setreuid available"); - (void)PerlProc_setuid(PL_delaymagic_uid); + rc = PerlProc_setuid(PL_delaymagic_uid); } # endif /* HAS_SETREUID */ #endif /* HAS_SETRESUID */ + + /* XXX $> et al currently silently ignore failures */ + PERL_UNUSED_VAR(rc); + tmp_uid = PerlProc_getuid(); tmp_euid = PerlProc_geteuid(); } if (PL_delaymagic & DM_GID) { #ifdef HAS_SETRESGID - (void)setresgid((PL_delaymagic & DM_RGID) ? PL_delaymagic_gid : (Gid_t)-1, + rc = setresgid((PL_delaymagic & DM_RGID) ? PL_delaymagic_gid : (Gid_t)-1, (PL_delaymagic & DM_EGID) ? PL_delaymagic_egid : (Gid_t)-1, (Gid_t)-1); #else # ifdef HAS_SETREGID - (void)setregid((PL_delaymagic & DM_RGID) ? PL_delaymagic_gid : (Gid_t)-1, + rc = setregid((PL_delaymagic & DM_RGID) ? PL_delaymagic_gid : (Gid_t)-1, (PL_delaymagic & DM_EGID) ? PL_delaymagic_egid : (Gid_t)-1); # else # ifdef HAS_SETRGID if ((PL_delaymagic & DM_GID) == DM_RGID) { - (void)setrgid(PL_delaymagic_gid); + rc = setrgid(PL_delaymagic_gid); PL_delaymagic &= ~DM_RGID; } # endif /* HAS_SETRGID */ # ifdef HAS_SETEGID if ((PL_delaymagic & DM_GID) == DM_EGID) { - (void)setegid(PL_delaymagic_egid); + rc = setegid(PL_delaymagic_egid); PL_delaymagic &= ~DM_EGID; } # endif /* HAS_SETEGID */ if (PL_delaymagic & DM_GID) { if (PL_delaymagic_gid != PL_delaymagic_egid) DIE(aTHX_ "No setregid available"); - (void)PerlProc_setgid(PL_delaymagic_gid); + rc = PerlProc_setgid(PL_delaymagic_gid); } # endif /* HAS_SETREGID */ #endif /* HAS_SETRESGID */ + + /* XXX $> et al currently silently ignore failures */ + PERL_UNUSED_VAR(rc); + tmp_gid = PerlProc_getgid(); tmp_egid = PerlProc_getegid(); } @@ -11762,6 +11762,7 @@ Perl_dirp_dup(pTHX_ DIR *const dp, CLONE_PARAMS *const param) DIR *ret; #ifdef HAS_FCHDIR + int rc = 0; DIR *pwd; const Direntry_t *dirent; char smallbuf[256]; @@ -11798,7 +11799,9 @@ Perl_dirp_dup(pTHX_ DIR *const dp, CLONE_PARAMS *const param) /* Now we should have two dir handles pointing to the same dir. */ /* Be nice to the calling code and chdir back to where we were. */ - fchdir(my_dirfd(pwd)); /* If this fails, then what? */ + rc = fchdir(my_dirfd(pwd)); + /* XXX If this fails, then what? */ + PERL_UNUSED_VAR(rc); /* We have no need of the pwd handle any more. */ PerlDir_close(pwd); @@ -336,7 +336,9 @@ # define ALLOC_THREAD_KEY \ STMT_START { \ if (pthread_key_create(&PL_thr_key, 0)) { \ - (void)write(2, STR_WITH_LEN("panic: pthread_key_create failed\n")); \ + int rc; \ + rc = write(2, STR_WITH_LEN("panic: pthread_key_create failed\n")); \ + PERL_UNUSED_VAR(rc); \ exit(1); \ } \ } STMT_END @@ -1595,10 +1595,13 @@ void Perl_croak_no_mem() { dTHX; + int rc; /* Can't use PerlIO to write as it allocates memory */ - (void)PerlLIO_write(PerlIO_fileno(Perl_error_log), + rc = PerlLIO_write(PerlIO_fileno(Perl_error_log), PL_no_mem, sizeof(PL_no_mem)-1); + /* silently ignore failures */ + PERL_UNUSED_VAR(rc); my_exit(1); } |