473,651 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bug in SosMan's getline_test

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.

Sep 11 '07 #1
38 1924
Friar Tuck <no****@invalid .comwrites:
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
Sep 11 '07 #2
Ben Pfaff said:
Friar Tuck <no****@invalid .comwrites:
>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
Sep 12 '07 #3
On 11 Sep 2007 at 23:30, Ben Pfaff wrote:
Friar Tuck <no****@invalid .comwrites:
>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?

Sep 12 '07 #4
On Sep 12, 10:59 am, Friar Tuck <nos...@invalid .comwrote:
On 11 Sep 2007 at 23:30, Ben Pfaff wrote:
Friar Tuck <nos...@invalid .comwrites:
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.
Sep 12 '07 #5
On Wed, 12 Sep 2007 19:59:32 +0200 (CEST), in comp.lang.c , Friar Tuck
<no****@invalid .comwrote:
>On 11 Sep 2007 at 23:30, Ben Pfaff wrote:
>Friar Tuck <no****@invalid .comwrites:
>>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
Sep 12 '07 #6
Friar Tuck wrote:
>
On 11 Sep 2007 at 23:30, Ben Pfaff wrote:
Friar Tuck <no****@invalid .comwrites:
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
Sep 12 '07 #7
user923005 wrote:
>
On Sep 12, 10:59 am, Friar Tuck <nos...@invalid .comwrote:
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
Sep 13 '07 #8
Friar Tuck wrote:
On 11 Sep 2007 at 23:30, Ben Pfaff wrote:
>Friar Tuck <no****@invalid .comwrites:
>>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

Sep 13 '07 #9

"Richard Heathfield" <rj*@see.sig.in validwrote in message
news:jY******** *************** *******@bt.com. ..
#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_FAILU RE);
return 0;
}

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

Sep 13 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
2702
by: Ashutosh Iddya | last post by:
Hi , I am performing an integer count of a particular operation in my program. After a sufficiently large value an overflow occurs. At the moment I have gone around the problem by declaring it as a double, even that has its limits. Is there a method of preventing this overflow or some method of recovering from it. Any help in this regard would be greatly appreciated. Thanking you.
0
8347
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8792
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8694
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8571
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1905
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.