strange bug that doesn't occur in Linux, OpenBSD or ITS

Mark Geisert mark@maxrnd.com
Sun Feb 19 00:29:00 GMT 2012


Jeremiah Bishop writes:
> the  bash commands used are:
> 1) gcc "cygwin puzzle.c" 
> 
> 2) ./a.out a b
> Now either version used on a file with a shorter set of lines, works just fine
but strangely, that single
> digit difference aborts the program without throwing any error on the sample
input or text files with
> similarly long lines.
> 
> Perhaps that has been covered before but 3 hours of searching the archives did
not yield any helpful results
> [perhaps I used the wrong search criteria? ]
> 
> any tips or hints on what has gone wrong will be helpful.

1. This has nothing to do with Cygwin, but rather basic programming safety
practices:

2. You aren't checking the result of malloc() to see if it's NULL before using
it.  The heap (where malloc() gets its memory) is not infinite and varies in
size between platforms.

3. You didn't say what happened when you ran the program, so I had to audit it
and run it and watch it laboriously consume memory until I ran out of patience.

4. You've coded functions nested inside main().  I haven't seen that practice 
in C language before but apparently it works.  Color me impressed.

That's all I've got.
HTH,

..mark


--
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



More information about the Cygwin mailing list