[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Fix for Microsoft compilers
From: |
Thomas Preud'homme |
Subject: |
Re: [Tinycc-devel] Fix for Microsoft compilers |
Date: |
Sun, 12 Apr 2015 21:40:15 +0800 |
User-agent: |
KMail/4.14.1 (Linux/3.16.0-4-amd64; KDE/4.14.2; x86_64; ; ) |
Le dimanche 12 avril 2015, 15:10:14 oldfaber a écrit :
> > Except that later there is "name = buf;" with name staying live out of
> > this if scope. So this change is not correct. It would be better to move
> > it out up a bit.
> >
> > Best regards,
> >
> > Thomas
>
> Yes, you are right, the patch is wrong.
>
> What about removing char buf[32] and replacing
> strcpy(buf, "__bound_");
> strcat(buf, name);
> name = buf;
>
> with
>
> if (strlen(name) + strlen("__bound_") <
> (unsigned)STRING_MAX_SIZE) {
> memmove(name + strlen("__bound_"), name, strlen(name));
> memcpy(name, "__bound_", strlen("__bound_"));
> }
Oh my, get_tok_str returns a pointer to a local variable. So the proper fix
would be to make get_tok_str take a CString as parameter and have the caller
allocate the buffer associated with the CString. And then it's just a matter of
allocating buf to STRING_MAX_SIZE.
Cheers,
Thomas
signature.asc
Description: This is a digitally signed message part.