:: Re: [DNG] Systemd Shims
Página superior
Eliminar este mensaje
Responder a este mensaje
Autor: Rainer Weikusat
Fecha:  
A: dng
Temas nuevos: [DNG] C coding subtlleties
Asunto: 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.