From: Kees Cook
> Sent: 27 August 2020 23:21
...
> 
> Agreed. This just makes me cringe. If the API design declares that when
> a show() callback starts, buf has been allocated with PAGE_SIZE bytes,
> then that's how the logic should proceed, and it should be using
> scnprintf...
> 
> show(...) {
>       size_t remaining = PAGE_SIZE;
> 
>       ...
>       remaining -= scnprintf(buf, remaining, "fmt", var args ...);
>       remaining -= scnprintf(buf, remaining, "fmt", var args ...);
>       remaining -= scnprintf(buf, remaining, "fmt", var args ...);

Not quite what you had in mind, maybe:
        char *end = buf + PAGE_SIZE;

        buf += scnprintf(buf, end - buf, ...);

        return PAGE_SIZE - (end - buf);

        David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, 
UK
Registration No: 1397386 (Wales)

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to