🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #126

Re: I am stumped on this one!!!

#126
From: Guy Harris
Date: Sun, 26 Jul 1992 02:14
18 lines
1123 bytes
>>		cp_line = (char *)malloc(sizeof(strlen(pars_wbuf)));
>
> You're allocing the sizeof an int, which is likely four bytes.
> You also forgot to alloc space for the '\0'. Try it again with:
>
>	cp_line = (char*)malloc(sizeof(strlen(pars_wbuf) + 1));

No, try it again with:

>	cp_line = (char*)malloc(strlen(pars_wbuf) + 1);

because, as you noted, the "sizeof" doesn't belong there - it turns the
argument into the size of the result of "strlen", which isn't the length
of the string.

(Also, try not leaving every single line of the original posting in your
followup; it makes it rather hard to find the stuff that *doesn't* come
from the original posting....)
Technical Details
Message-ID: <13744@auspex-gw.auspex.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!auspex-gw!guy
References: <1992Jul24.204944.18516@cbfsb.cb.att.com> <Brx394.4qL@undergrad.math.waterloo.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!auspex-gw!guy
From: guy@Auspex.COM (Guy Harris)
Newsgroups: comp.unix.programmer
Subject: Re: I am stumped on this one!!!
Message-ID: <13744@auspex-gw.auspex.com>
Date: 26 Jul 92 02:14:54 GMT
References: <1992Jul24.204944.18516@cbfsb.cb.att.com> <Brx394.4qL@undergrad.math.waterloo.edu>
Sender: news@auspex-gw.auspex.com
Organization: Auspex Systems, Santa Clara
Lines: 18
Nntp-Posting-Host: auspex.auspex.com