delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2005/07/07/08:31:16

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: pointers in Strucrure assignment problem
Date: 7 Jul 2005 12:16:33 GMT
Lines: 30
Message-ID: <3j4kp1Foa1tsU4@news.dfncis.de>
References: <1120713425 DOT 526371 DOT 222910 AT g47g2000cwa DOT googlegroups DOT com> <TG4ze.17390$pa3 DOT 15032 AT newsread2 DOT news DOT atl DOT earthlink DOT net>
X-Trace: news.dfncis.de +s9ooGMryXg+zACX6BOoaAyKB08Ov5gP6ZeFOOe/KDn4J1pX3a/H3++dS4
X-Orig-Path: not-for-mail
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Martin Ambuhl <mambuhl AT earthlink DOT net> wrote:
> >               LD[i].LinePtr="";

> The second of these causes you to
> 1) lose the value returned by calloc
> 2) create a memory leak
> 3) assign LD[i].LinePtr to point to the string literal "",

and 4) evokes undefined behaviour in the next line, where he writes
something to LinePtr[0], i.e. tries to modify a string literal.

>     *LD[i].LinePtr = 0;

That one's a bit gratuitously obfuscated.

	LD[i].LinePtr[0] = '\0';

is almost certainly clearer to the OP.

Actually, the next line in the OP's source suggested that he actually
wants to do something like

	strcpy(LD[i].LinePtr, "\n");

(he wrote a 13 in there, which is actually '\r', but you get the
picture...)

-- 
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019