Hi Daniel,
Thanks for your reply. I was just using that as an example - I forgot the
const modifier.
What I really need to know is how to stop lclint from complaining about the
assignment.
Steve
> -----Original Message-----
> From: Daniel Barker [mailto:[EMAIL PROTECTED]]
> Sent: Monday, November 26, 2001 2:17 AM
> To: Steve
> Cc: [EMAIL PROTECTED]
> Subject: Re: NEWBIE - structs containing pointers
>
>
> One very dangerous thing about your code is you have an unqualified
> "char *" pointing to a string literal. String literals must never be
> modified. so it would be better to declare the struct member as
>
> const char *Foo;
>
> or alternatively, leave it un-const but have it point to the start of a
> "normal" char array rather than a string literal, e.g.
>
> bar = malloc(sizeof(struct Frozz));
> bar->Foo = malloc(strlen("Test") + 1);
> strcpy(bar->Foo, "Test");
>
> The array can then be modified.
>
> Warning: I've not tested this.
>
> Daniel.
>
> On Sun, 25 Nov 2001, Steve wrote:
>
> >
> > Hi all,
> >
> > I was just wondering the 'correct' method to handle something like:
> > struct Frozz {
> > int a;
> > char *Foo;
> > };
> >
> > struct Frozz *bar;
> > bar = malloc(sizeof(struct Frozz));
> > bar->Foo = "Test";
> >
> > LCLint complaines about implicit only not free'd or some such on the
> > 'bar->Foo...' line. Could someone
> > point out the common way of handling such cases ?
> >
> > Also, is there a 'cookbook' somewhere with common program
> > constructs/methods/etc and how to decorate them ?
> > for instance, a function returning a pointer to memory it dynamically
> > allocates ? I found the users guide (on-line v2.4 html) very
> in-depth on
> > the WHAT lclint does, but very light on HOW to use it. Was
> there another
> > doc/faq/guide I should be RTFM'ing ??
> >
> > Steve
>
>