From 8b0dea507b8f946d8546917b8fda74bfbf233ac0 Mon Sep 17 00:00:00 2001 From: Dave Mitchell Date: Sun, 22 Jun 2008 19:05:31 +0000 Subject: [PATCH] Incorrect variable reported in uninitialized value warning. Ops that can return undef even for defined args, could mistakenly warn that the arg was undefined. p4raw-id: //depot/perl@34077 --- sv.c | 72 +++++++++++++++++++++++++++- t/lib/warnings/9uninit | 127 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 197 insertions(+), 2 deletions(-) diff --git a/sv.c b/sv.c index 9b23592..37c60cf 100644 --- a/sv.c +++ b/sv.c @@ -12594,8 +12594,75 @@ S_find_uninit_var(pTHX_ OP* obase, SV* uninit_sv, bool match) case OP_ENTEREVAL: /* could be eval $undef or $x='$undef'; eval $x */ case OP_RV2SV: - case OP_CUSTOM: - match = 1; /* XS or custom code could trigger random warnings */ + case OP_CUSTOM: /* XS or custom code could trigger random warnings */ + + /* the following ops are capable of returning PL_sv_undef even for + * defined arg(s) */ + + case OP_BACKTICK: + case OP_PIPE_OP: + case OP_FILENO: + case OP_BINMODE: + case OP_TIED: + case OP_GETC: + case OP_SYSREAD: + case OP_SEND: + case OP_IOCTL: + case OP_SOCKET: + case OP_SOCKPAIR: + case OP_BIND: + case OP_CONNECT: + case OP_LISTEN: + case OP_ACCEPT: + case OP_SHUTDOWN: + case OP_SSOCKOPT: + case OP_GETPEERNAME: + case OP_FTRREAD: + case OP_FTRWRITE: + case OP_FTREXEC: + case OP_FTROWNED: + case OP_FTEREAD: + case OP_FTEWRITE: + case OP_FTEEXEC: + case OP_FTEOWNED: + case OP_FTIS: + case OP_FTZERO: + case OP_FTSIZE: + case OP_FTFILE: + case OP_FTDIR: + case OP_FTLINK: + case OP_FTPIPE: + case OP_FTSOCK: + case OP_FTBLK: + case OP_FTCHR: + case OP_FTTTY: + case OP_FTSUID: + case OP_FTSGID: + case OP_FTSVTX: + case OP_FTTEXT: + case OP_FTBINARY: + case OP_FTMTIME: + case OP_FTATIME: + case OP_FTCTIME: + case OP_READLINK: + case OP_OPEN_DIR: + case OP_READDIR: + case OP_TELLDIR: + case OP_SEEKDIR: + case OP_REWINDDIR: + case OP_CLOSEDIR: + case OP_GMTIME: + case OP_ALARM: + case OP_SEMGET: + case OP_GETLOGIN: + case OP_UNDEF: + case OP_SUBSTR: + case OP_AEACH: + case OP_EACH: + case OP_SORT: + case OP_CALLER: + case OP_DOFILE: + match = 1; goto do_op; case OP_ENTERSUB: @@ -12607,6 +12674,7 @@ S_find_uninit_var(pTHX_ OP* obase, SV* uninit_sv, bool match) Need a better fix at dome point. DAPM 11/2007 */ break; + case OP_POS: /* def-ness of rval pos() is independent of the def-ness of its arg */ if ( !(obase->op_flags & OPf_MOD)) diff --git a/t/lib/warnings/9uninit b/t/lib/warnings/9uninit index 16ce1b8..2073f92 100644 --- a/t/lib/warnings/9uninit +++ b/t/lib/warnings/9uninit @@ -1411,3 +1411,130 @@ EXPECT Use of uninitialized value in reverse at - line 4. Use of uninitialized value $r1 in reverse at - line 5. Use of uninitialized value $r2 in reverse at - line 6. +######## +use warnings 'uninitialized'; +# +# ops that can return undef for defined args +# +my $nofile = '/no/such/file'; +my $nocmd = '/no/such/command'; +my $v; +$v = 1 + `$nocmd`; +$v = 1 + qx($nocmd); +my $f = ""; +$v = 1 + open($f, $nofile); +# *** pipe() not tested +$v = 1 + fileno($nofile); +$v = 1 + binmode($nofile); +$v = 1 + tied($nofile); +$v = 1 + getc($nofile); +$v = 1 + sysread($nofile, my $buf,1); +$v = 1 + eval { send($nofile, $buf,0) }; +# *** ioctl not tested +# *** socket not tested +# *** socketpair not tested +# *** bind not tested +# *** connect not tested +# *** listen not tested +$v = 1 + eval { accept($fh, $nofile) }; +# *** shutdown not tested +# *** setsockopt not tested +# *** getpeername not tested +$v = 1 + (-r $nofile); +$v = 1 + (-w $nofile); +$v = 1 + (-x $nofile); +$v = 1 + (-o $nofile); +$v = 1 + (-R $nofile); +$v = 1 + (-W $nofile); +$v = 1 + (-X $nofile); +$v = 1 + (-O $nofile); +$v = 1 + (-e $nofile); +$v = 1 + (-z $nofile); +$v = 1 + (-s $nofile); +$v = 1 + (-f $nofile); +$v = 1 + (-d $nofile); +$v = 1 + (-l $nofile); +$v = 1 + (-p $nofile); +$v = 1 + (-S $nofile); +$v = 1 + (-b $nofile); +$v = 1 + (-c $nofile); +$v = 1 + (-t $nofile); +$v = 1 + (-u $nofile); +$v = 1 + (-g $nofile); +$v = 1 + (-k $nofile); +$v = 1 + (-T $nofile); +$v = 1 + (-B $nofile); +$v = 1 + (-M $nofile); +$v = 1 + (-A $nofile); +$v = 1 + (-C $nofile); +$v = 1 + eval { readlink $nofile }; +$v = 1 + opendir($f, $nofile); +# *** readdir not tested +# *** telldir not tested +# *** seekdir not tested +# *** rewinddir not tested +# *** closedir not tested +# *** gmtime not tested +# *** alarm not tested +# *** semget not tested +# *** getlogin not tested +$v = 1 + undef; +my $x = 1; $v = 1 + undef($x); +my $emptys = ""; +$v = 1 + substr($emptys,2,1); +my @emptya; +$v = 1 + each @emptya; +my @emptyh; +$v = 1 + each %emptyh; +$v = 1 + sort @emptya; +my $zero = 0; $v = 1 + caller($zero); +$v = 1 + do $nofile; + +EXPECT +Use of uninitialized value in addition (+) at - line 8. +Use of uninitialized value in addition (+) at - line 9. +Use of uninitialized value in addition (+) at - line 11. +Use of uninitialized value in addition (+) at - line 13. +Use of uninitialized value in addition (+) at - line 14. +Use of uninitialized value in addition (+) at - line 15. +Use of uninitialized value in addition (+) at - line 16. +Use of uninitialized value in addition (+) at - line 17. +Use of uninitialized value in addition (+) at - line 18. +Use of uninitialized value in addition (+) at - line 25. +Use of uninitialized value in addition (+) at - line 29. +Use of uninitialized value in addition (+) at - line 30. +Use of uninitialized value in addition (+) at - line 31. +Use of uninitialized value in addition (+) at - line 32. +Use of uninitialized value in addition (+) at - line 33. +Use of uninitialized value in addition (+) at - line 34. +Use of uninitialized value in addition (+) at - line 35. +Use of uninitialized value in addition (+) at - line 36. +Use of uninitialized value in addition (+) at - line 37. +Use of uninitialized value in addition (+) at - line 38. +Use of uninitialized value in addition (+) at - line 39. +Use of uninitialized value in addition (+) at - line 40. +Use of uninitialized value in addition (+) at - line 41. +Use of uninitialized value in addition (+) at - line 42. +Use of uninitialized value in addition (+) at - line 43. +Use of uninitialized value in addition (+) at - line 44. +Use of uninitialized value in addition (+) at - line 45. +Use of uninitialized value in addition (+) at - line 46. +Use of uninitialized value in addition (+) at - line 47. +Use of uninitialized value in addition (+) at - line 48. +Use of uninitialized value in addition (+) at - line 49. +Use of uninitialized value in addition (+) at - line 50. +Use of uninitialized value in addition (+) at - line 51. +Use of uninitialized value in addition (+) at - line 52. +Use of uninitialized value in addition (+) at - line 53. +Use of uninitialized value in addition (+) at - line 54. +Use of uninitialized value in addition (+) at - line 55. +Use of uninitialized value in addition (+) at - line 56. +Use of uninitialized value in addition (+) at - line 57. +Use of uninitialized value in addition (+) at - line 67. +Use of uninitialized value in addition (+) at - line 68. +Use of uninitialized value in addition (+) at - line 70. +Use of uninitialized value in addition (+) at - line 72. +Use of uninitialized value in addition (+) at - line 74. +Use of uninitialized value in addition (+) at - line 75. +Use of uninitialized value in addition (+) at - line 76. +Use of uninitialized value in addition (+) at - line 77. -- 2.7.4