:: Re: [DNG] Systemd Shims
Top Pagina
Delete this message
Reply to this message
Auteur: Rainer Weikusat
Datum:  
Aan: dng
Nieuwe Onderwerpen: [DNG] C coding subtlleties
Onderwerp: Re: [DNG] Systemd Shims
Hendrik Boom <hendrik@???> writes:

> On Fri, Aug 21, 2015 at 12:51:55PM +0100, Rainer Weikusat wrote:
>>
>> That's going to work with this particular problem which you incorrectly
>> (the original path wasn't a macro) reduced to appending a string of
>> unknown length to a constant string. Taking this into account, a
>> solution without snprintf would become something like
>>
>> #define PATH "/tmp/"
>>
>> char *p;
>>
>> p = alloca(sizeof(PATH) + strlen(argv[1]));
>
> Should that be
> p = alloca(sizeof(PATH) + strlen(argv[1]) + 1);
>
>> sprintf(p, "%s%s", PATH, argv[1]);
>
> so there's space for the terminating '\0'?


The size of a string literal includes the terminating 0.