Re: isprint core dump

2012-01-24 Thread Csaba Raduly
On Mon, Jan 23, 2012 at 10:34 PM, Nellis, Kenneth  wrote:
 From: Eric Blake

 No, but it DOES come from POSIX:
 http://pubs.opengroup.org/onlinepubs/9699919799/functions/isprint.html

 And cygwin's behavior matches POSIX on this point; the bug is in your
 program, not cygwin.

 Call me blown away by the level of support this function that
 dumps core is getting, when it could act sanely (IMHO) with a
 simple if statement! So much for defensive programming.

Like it or not, this is how C works. If you want defensive programming
with bounds checking and stuff, try Pascal or Java.

The man page of isprint states:
int isprint(int c);
These functions check whether c, which must have the value of an
unsigned char or EOF...

^^^
If the argument has any other value, the behavior is undefined.

This is a contract between the library and you, the library user. You
promise to pass an argument between -1 and 255. isprint promises to
return a correct result.

You didn't keep your promise, so isprint is free to do anything it
wants including, but not limited to, opening your web browser at
http://nooo.com/

Csaba
-- 
GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++
The Tao of math: The numbers you can count are not the real numbers.
Life is complex, with real and imaginary parts.
Ok, it boots. Which means it must be bug-free and perfect.  -- Linus Torvalds
People disagree with me. I just ignore them. -- Linus Torvalds

--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple



Re: isprint core dump

2012-01-23 Thread Ryan Johnson

On 23/01/2012 3:16 PM, Nellis, Kenneth wrote:

I haven't had the chance to try under Linux, but
   isprint(3055872)
is core-dumping on me.


From the isprint() man page:

/c/ ... must have the value of an /unsigned char/ or *EOF*


The test case probably overruns some internal table by 3MB or so.

Ryan


--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple



Re: isprint core dump

2012-01-23 Thread Jon Clugston
On Mon, Jan 23, 2012 at 3:16 PM, Nellis, Kenneth
kenneth.nel...@acs-inc.com wrote:
 I haven't had the chance to try under Linux, but
  isprint(3055872)
 is core-dumping on me. Here's a STC:

 ==
 #include stdio.h
 #include ctype.h

 int main (void)
 {
    int a = 3055872;
    int b = isprint(a);
    printf (%d %d\n, a, b);
    return 0;
 }
 ==


Whatever you are trying to do, you are using the wrong tool for the
job.  isprint() should be passed a char, in fact it only works on
ASCII characters.

--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple



RE: isprint core dump

2012-01-23 Thread Nellis, Kenneth
From: Ryan Johnson
 From the isprint() man page:
 /c/ ... must have the value of an /unsigned char/ or *EOF*

FWIW, that didn't come from the cygwin man page.

--Ken Nellis

--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple



Re: isprint core dump

2012-01-23 Thread Eric Blake
On 01/23/2012 01:44 PM, Nellis, Kenneth wrote:
 From: Ryan Johnson
  From the isprint() man page:
 /c/ ... must have the value of an /unsigned char/ or *EOF*
 
 FWIW, that didn't come from the cygwin man page.

No, but it DOES come from POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/isprint.html

And cygwin's behavior matches POSIX on this point; the bug is in your
program, not cygwin.

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


RE: isprint core dump

2012-01-23 Thread Nellis, Kenneth
From: Eric Blake

 No, but it DOES come from POSIX:
 http://pubs.opengroup.org/onlinepubs/9699919799/functions/isprint.html

 And cygwin's behavior matches POSIX on this point; the bug is in your
 program, not cygwin.

Call me blown away by the level of support this function that
dumps core is getting, when it could act sanely (IMHO) with a 
simple if statement! So much for defensive programming.

--Ken Nellis


--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple



Re: isprint core dump

2012-01-23 Thread Eric Blake
On 01/23/2012 02:34 PM, Nellis, Kenneth wrote:
 From: Eric Blake
 
 No, but it DOES come from POSIX:
 http://pubs.opengroup.org/onlinepubs/9699919799/functions/isprint.html

 And cygwin's behavior matches POSIX on this point; the bug is in your
 program, not cygwin.
 
 Call me blown away by the level of support this function that
 dumps core is getting, when it could act sanely (IMHO) with a 
 simple if statement! So much for defensive programming.

If you want defensive programming, write the defense into your program -
don't call functions with invalid arguments in the first place.  It
costs time to process an if() statement that would be reached by every
single caller, when 99.99% of the callers already comply with the
standards.  Meanwhile, since cygwin inherits its isprint()
implementation from newlib, and newlib caters to embedded systems, you
will be fighting an uphill battle to add anything that adds bloat that
slows down an embedded client.  We already get complaints about cygwin
being too slow, and you are proposing making it slower by doing
safety-net checking for buggy programs.  So we ask instead that you put
the if() in your program, and not in the core isprint() implementation.

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: isprint core dump

2012-01-23 Thread Ryan Johnson

On 23/01/2012 4:39 PM, Eric Blake wrote:

On 01/23/2012 02:34 PM, Nellis, Kenneth wrote:

From: Eric Blake


No, but it DOES come from POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/isprint.html

And cygwin's behavior matches POSIX on this point; the bug is in your
program, not cygwin.

Call me blown away by the level of support this function that
dumps core is getting, when it could act sanely (IMHO) with a
simple if statement! So much for defensive programming.

If you want defensive programming, write the defense into your program -
don't call functions with invalid arguments in the first place.  It
costs time to process an if() statement that would be reached by every
single caller, when 99.99% of the callers already comply with the
standards.
That, and the if() would almost certainly mask the bug -- there's no 
value isprint() can return to signal an error, and if the sad state of 
errno and error code checking in general is any indication, the error 
condition would be ignored by 99.99% of buggy callers even if isprint() 
did signal it in some way.


I, for one, prefer my invalid code to trigger a nice, predictable seg 
fault immediately, rather than returning undefined results and/or 
causing malloc() to barf at some indeterminate point in the future.


Ryan


--
Problem reports:   http://cygwin.com/problems.html
FAQ:   http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple