Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Bug in SosMan's getline_test

Reply
Thread Tools

Bug in SosMan's getline_test

 
 
Friar Tuck
Guest
Posts: n/a
 
      09-11-2007
I believe I have found a bug in Dr Sosman's getline_test program, which
is one of the official newsgroup programs. Debugging information
follows.

$ gdb ./getline_test
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i586-suse-linux"...Using host libthread_db library
"/lib/tls/libthread_db.so.1".

(gdb) r
Starting program: /tmp/getline_test

Program received signal SIGSEGV, Segmentation fault.
0x4008febf in getdelim () from /lib/tls/libc.so.6
(gdb) bt
#0 0x4008febf in getdelim () from /lib/tls/libc.so.6
#1 0x4008d844 in getline () from /lib/tls/libc.so.6
#2 0x080486b2 in verify (file=0x804a008, st=0xbfffee70, special=0) at
getline_test.c:44
#3 0x0804891d in main () at getline_test.c:103
(gdb) f 2
#2 0x080486b2 in verify (file=0x804a008, st=0xbfffee70, special=0) at
getline_test.c:44
44 buff = getline(file);
(gdb) p *file
$1 = {_flags = -72539008,
_IO_read_ptr = 0x40018000 'n' <repeats 25 times>, "\n", 'd' <repeats 174 times>...,
_IO_read_end = 0x40018000 'n' <repeats 25 times>, "\n", 'd' <repeats 174 times>...,
_IO_read_base = 0x40018000 'n' <repeats 25 times>, "\n", 'd' <repeats 174 times>...,
_IO_write_base = 0x40018000 'n' <repeats 25 times>, "\n", 'd' <repeats 174 times>...,
_IO_write_ptr = 0x40018000 'n' <repeats 25 times>, "\n", 'd' <repeats 174 times>...,
_IO_write_end = 0x40018000 'n' <repeats 25 times>, "\n", 'd' <repeats 174 times>...,
_IO_buf_base = 0x40018000 'n' <repeats 25 times>, "\n", 'd' <repeats 174 times>...,
_IO_buf_end = 0x40019000 'b' <repeats 200 times>...,
_IO_save_base = 0x0,
_IO_backup_base = 0x0, _IO_save_end = 0x0, _markers = 0x0,
_chain = 0x40151460,
_fileno = 6, _flags2 = 0, _old_offset = 0, _cur_column = 0,
_vtable_offset = 0 '\0',
_shortbuf = "", _lock = 0x804a0a0, _offset = 0, __pad1 =
0x0, __pad2 = 0x804a0ac,
_mode = -1, _unused2 = '\0' <repeats 51 times>}
(gdb)

It looks to me like the _flags field of file has become corrupted - it
seems to have an odd value.

 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      09-11-2007
Friar Tuck <> writes:

> I believe I have found a bug in Dr Sosman's getline_test program, which
> is one of the official newsgroup programs.


There is no such thing as an "official newsgroup program", at
least not in comp.lang.c

> (gdb) bt
> #0 0x4008febf in getdelim () from /lib/tls/libc.so.6
> #1 0x4008d844 in getline () from /lib/tls/libc.so.6
> #2 0x080486b2 in verify (file=0x804a008, st=0xbfffee70, special=0) at
> getline_test.c:44
> #3 0x0804891d in main () at getline_test.c:103
> (gdb) f 2
> #2 0x080486b2 in verify (file=0x804a008, st=0xbfffee70, special=0) at
> getline_test.c:44
> 44 buff = getline(file);


It seems very unlikely that Eric would have written his code to
call into the "getline" function in the GNU C library, which is
what this backtrace is showing. I think that you did not compile
and link the test program correctly.

GNU lib'c getline and Eric's getline evidently have different
interfaces, judging from the line of source code above.
--
"If I've told you once, I've told you LLONG_MAX times not to
exaggerate."
--Jack Klein
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      09-12-2007
Ben Pfaff said:

> Friar Tuck <> writes:
>
>> I believe I have found a bug in Dr Sosman's getline_test program,
>> which is one of the official newsgroup programs.

>
> There is no such thing as an "official newsgroup program", at
> least not in comp.lang.c


There is one. It is:

#include <stdio.h>

int main(void)
{
puts("Hello, world!");
return 0;
}

(or minor variations thereof).

<snip>

>> 44 buff = getline(file);

>
> It seems very unlikely that Eric would have written his code to
> call into the "getline" function in the GNU C library, which is
> what this backtrace is showing. I think that you did not compile
> and link the test program correctly.


Quite so. I think Eric is guilty of poor name choice here, but no more.

> GNU lib'c getline and Eric's getline evidently have different
> interfaces, judging from the line of source code above.


Alas, I think Eric forgot Einstein's dictum that "it should be as simple
as possible, but no simpler". Eric's function is simpler than possible.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
Friar Tuck
Guest
Posts: n/a
 
      09-12-2007
On 11 Sep 2007 at 23:30, Ben Pfaff wrote:
> Friar Tuck <> writes:
>
>> I believe I have found a bug in Dr Sosman's getline_test program, which
>> is one of the official newsgroup programs.

>
> There is no such thing as an "official newsgroup program", at
> least not in comp.lang.c


Well, it's listed on the group website, so I'd say that's official.

>
>> (gdb) bt
>> #0 0x4008febf in getdelim () from /lib/tls/libc.so.6
>> #1 0x4008d844 in getline () from /lib/tls/libc.so.6
>> #2 0x080486b2 in verify (file=0x804a008, st=0xbfffee70, special=0) at
>> getline_test.c:44
>> #3 0x0804891d in main () at getline_test.c:103
>> (gdb) f 2
>> #2 0x080486b2 in verify (file=0x804a008, st=0xbfffee70, special=0) at
>> getline_test.c:44
>> 44 buff = getline(file);

>
> It seems very unlikely that Eric would have written his code to
> call into the "getline" function in the GNU C library, which is
> what this backtrace is showing. I think that you did not compile
> and link the test program correctly.
>
> GNU lib'c getline and Eric's getline evidently have different
> interfaces, judging from the line of source code above.


I don't believe there's a standard library function called getline. If
there is, wouldn't it be better if Dr Sosman's version either had a
different name, or followed the same interface?

 
Reply With Quote
 
user923005
Guest
Posts: n/a
 
      09-12-2007
On Sep 12, 10:59 am, Friar Tuck <nos...@invalid.com> wrote:
> On 11 Sep 2007 at 23:30, Ben Pfaff wrote:
>
> > Friar Tuck <nos...@invalid.com> writes:

>
> >> I believe I have found a bug in Dr Sosman's getline_test program, which
> >> is one of the official newsgroup programs.

>
> > There is no such thing as an "official newsgroup program", at
> > least not in comp.lang.c

>
> Well, it's listed on the group website, so I'd say that's official.


What's the group website?

> >> (gdb) bt
> >> #0 0x4008febf in getdelim () from /lib/tls/libc.so.6
> >> #1 0x4008d844 in getline () from /lib/tls/libc.so.6
> >> #2 0x080486b2 in verify (file=0x804a008, st=0xbfffee70, special=0) at
> >> getline_test.c:44
> >> #3 0x0804891d in main () at getline_test.c:103
> >> (gdb) f 2
> >> #2 0x080486b2 in verify (file=0x804a008, st=0xbfffee70, special=0) at
> >> getline_test.c:44
> >> 44 buff = getline(file);

>
> > It seems very unlikely that Eric would have written his code to
> > call into the "getline" function in the GNU C library, which is
> > what this backtrace is showing. I think that you did not compile
> > and link the test program correctly.

>
> > GNU lib'c getline and Eric's getline evidently have different
> > interfaces, judging from the line of source code above.

>
> I don't believe there's a standard library function called getline.


There isn't. But there is a GNU version that is very popular among
POSIX platforms.
http://www.gnu.org/software/libc/man...ine-Input.html

> If
> there is, wouldn't it be better if Dr Sosman's version either had a
> different name, or followed the same interface?


Right. But there isn't a standard C function called getline(). There
is a popular one, so it still might be a good idea to change the name
a bit.


 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      09-12-2007
On Wed, 12 Sep 2007 19:59:32 +0200 (CEST), in comp.lang.c , Friar Tuck
<> wrote:

>On 11 Sep 2007 at 23:30, Ben Pfaff wrote:
>> Friar Tuck <> writes:
>>
>>> I believe I have found a bug in Dr Sosman's getline_test program, which
>>> is one of the official newsgroup programs.

>>
>> There is no such thing as an "official newsgroup program", at
>> least not in comp.lang.c

>
>Well, it's listed on the group website, so I'd say that's official.


There /is/ no group website. Do you mean the CLC wiki? Thats an
unofficial effort maintained by some of the regulars here, but by no
means officially sanctioned (how could it be, there's no elected
officers of this unmoderated group).
>>
>> GNU lib'c getline and Eric's getline evidently have different
>> interfaces, judging from the line of source code above.

>
>I don't believe there's a standard library function called getline.


Correct. However what Ben said was "GNU libc's getline". GNU evidently
provide a nonstandard 'getline' function with different semantics to
Eric's.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      09-12-2007
Friar Tuck wrote:
>
> On 11 Sep 2007 at 23:30, Ben Pfaff wrote:
> > Friar Tuck <> writes:
> >
> >> I believe I have found a bug in
> >> Dr Sosman's getline_test program,


Is he really a doctor?

> >> which is one of the official newsgroup programs.

> >
> > There is no such thing as an "official newsgroup program", at
> > least not in comp.lang.c

>
> Well, it's listed on the group website, so I'd say that's official.


There is no such thing as "the group website".

> > GNU lib'c getline


> I don't believe there's a standard library function called getline.


There isn't.
What is your native language?

--
pete
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      09-13-2007
Friar Tuck wrote:
> On 11 Sep 2007 at 23:30, Ben Pfaff wrote:
>> Friar Tuck <> writes:
>>
>>> I believe I have found a bug in Dr Sosman's getline_test program,
>>> which is one of the official newsgroup programs.

>>
>> There is no such thing as an "official newsgroup program", at
>> least not in comp.lang.c

>
> Well, it's listed on the group website, so I'd say that's official.


There is no such thing as a 'group website'.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      09-13-2007
user923005 wrote:
>
> On Sep 12, 10:59 am, Friar Tuck <nos...@invalid.com> wrote:


> > I don't believe there's a standard library function called getline.

>
> There isn't. But there is a GNU version that is very popular among
> POSIX platforms.
> http://www.gnu.org/software/libc/man...ine-Input.html


I have a somewhat similar one:

http://www.mindspring.com/~pfilandr/...ine/get_line.c

> > If there is,
> > wouldn't it be better if Dr Sosman's version either had a
> > different name, or followed the same interface?

>
> Right. But there isn't a standard C function called getline(). There
> is a popular one, so it still might be a good idea to change the name
> a bit.


I changed the name of my function a little bit.

--
pete
 
Reply With Quote
 
Malcolm McLean
Guest
Posts: n/a
 
      09-13-2007

"Richard Heathfield" <> wrote in message
news:...
> #include <stdio.h>
>
> int main(void)
> {
> puts("Hello, world!");
> return 0;
> }
>
> (or minor variations thereof).
>

Buggy code is highly frowned on here.
Your progrm returns a success status if the puts operation fails.
It should be

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
if(puts("Hello world!") == EOF)
exit(EXIT_FAILURE);
return 0;
}

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
*bug* *bug* *bug* David Raleigh Arnold Firefox 12 04-02-2007 03:13 AM
ASP.NET Login control bug or SQL 2005 bug? RedEye ASP .Net 2 12-13-2005 10:57 AM
Re: BUG? OR NOT A BUG? John ASP .Net 2 09-21-2005 10:31 AM
Bug Parade Bug 4953793 Michel Joly de Lotbiniere Java 4 12-02-2003 05:05 AM
how to report bug to g++ ? got a bug and fixed up source code DarkSpy C++ 4 06-27-2003 09:05 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57