perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philippe M. Chiasson" <go...@ectoplasm.org>
Subject Re: confusing error message patch
Date Fri, 10 Mar 2006 23:14:16 GMT
Geoffrey Young wrote:
> Philippe M. Chiasson wrote:
>>Frank Wiles wrote:
>>
>>> Hey Everyone, 
>>>
>>> Saw the thread about $r->read($buf,0) and figured it would be wise
>>> to fix the error message to keep someone else from getting confused. 
>>>
>>> Here is a small patch to change "The LENGTH argument can't be
>>> negative" to "The LENGTH argument can't be negative or zero".  
>>
>>How about one of these ?
>>
>>"The LENGTH argument must be a positive number"
>>"The LENGTH argument must be > 0"
>>"The LENGTH argument must be >= 1"
>>"The LENGTH argument must be greater than zero"
> 
> have we actually demonstrated that $r->read($buf,0) is an error?

Good point, absolutely not demonstrated. Can we assume that if you
try to $r->read($buf, 0), nothing interesting will happen?

>  almost
> definitely useless, sure, but an error?  or maybe the problem is a loop
> might read and return true indefinitely, so
> 
>   while ($r->read($buf,$len)) { ... }
> 
> would be bad?

I would think $r->read() returns the number of bytes read, so if you try to
read 0, you succeed in reading 0 bytes, you get 0 back, and your loop aborts.

Index: xs/Apache2/RequestIO/Apache2__RequestIO.h
===================================================================
--- xs/Apache2/RequestIO/Apache2__RequestIO.h   (revision 384940)
+++ xs/Apache2/RequestIO/Apache2__RequestIO.h   (working copy)
@@ -239,9 +239,12 @@
         sv_setpvn(buffer, "", 0);
     }

-    if (len <= 0) {
+    if (len < 0) {
         Perl_croak(aTHX_ "The LENGTH argument can't be negative");
     }
+    else if (0 == len) {
+        return newSViv(0);
+    }

     /* XXX: need to handle negative offset */
     /* XXX: need to pad with \0 if offset > size of the buffer */


--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

Mime
View raw message