From: Gisle Aas <gisle@aas.no>
Date: Fri, 21 Oct 2005 05:24:30 +0000 (-0700)
Subject: wrong maxlen in sselect [PATCH]
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4ef2275c8517a5b084d75f6179d5b49f77f76d2c;p=p5sagit%2Fp5-mst-13.2.git

wrong maxlen in sselect [PATCH]
Message-ID: <lrzmp312ip.fsf@caliper.activestate.com>

Plus a regression test for the new warning.

p4raw-id: //depot/perl@25813
---

diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index 817503b..42a1fcb 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -2628,6 +2628,12 @@ to UTC.  If it's not, define the logical name
 F<SYS$TIMEZONE_DIFFERENTIAL> to translate to the number of seconds which
 need to be added to UTC to get local time.
 
+=item Non-string passed as bitmask
+
+(W misc) A number has been passed as a bitmask argument to select().
+Use the vec() function to construct the file descriptor bitmasks for
+select. See L<perlfunc/select>
+
 =item Null filename used
 
 (F) You can't require the null filename, especially because on many
diff --git a/pp_sys.c b/pp_sys.c
index c2ae681..cf6a862 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1037,8 +1037,13 @@ PP(pp_sselect)
 	    if (SvREADONLY(sv))
 		DIE(aTHX_ PL_no_modify);
 	}
-	if (!SvPOK(sv))
+	if (!SvOK(sv))
 	    continue;
+	if (!SvPOK(sv)) {
+	    if (ckWARN(WARN_MISC))
+                Perl_warner(aTHX_ packWARN(WARN_MISC), "Non-string passed as bitmask");
+	    SvPV_force_nolen(sv);	/* force string conversion */
+	}
 	j = SvCUR(sv);
 	if (maxlen < j)
 	    maxlen = j;
@@ -1092,8 +1097,7 @@ PP(pp_sselect)
 	    fd_sets[i] = 0;
 	    continue;
 	}
-	else if (!SvPOK(sv))
-	    SvPV_force_nolen(sv);	/* force string conversion */
+	assert(SvPOK(sv));
 	j = SvLEN(sv);
 	if (j < growsize) {
 	    Sv_Grow(sv, growsize);
diff --git a/t/lib/warnings/pp_sys b/t/lib/warnings/pp_sys
index 881e81e..d84ff75 100644
--- a/t/lib/warnings/pp_sys
+++ b/t/lib/warnings/pp_sys
@@ -103,6 +103,8 @@
 
   getc() on closed filehandle			[pp_getc]
 
+  Non-string passed as bitmask			[pp_sselect]
+
 __END__
 # pp_sys.c [pp_untie]
 use warnings 'untie' ;
@@ -446,3 +448,12 @@ EXPECT
 getc() on unopened filehandle FOO at - line 3.
 getc() on closed filehandle STDIN at - line 5.
 getc() on closed filehandle FH2 at - line 12.
+########
+# pp_sys.c [pp_sselect]
+use warnings 'misc';
+$x = 1;
+select $x, undef, undef, undef;
+no warnings 'misc';
+select $x, undef, undef, undef;
+EXPECT
+Non-string passed as bitmask at - line 4.