> On January 22, 2016 at 4:34 PM Rainer Weikusat
> <rainerweikusat@???> wrote:
>
> Can the effect of the following C function
>
> static void print_start(char const *name, char const *what)
> {
> char *buf, *p;
> unsigned name_len, what_len, total;
>
> name_len = strlen(name);
> what_len = strlen(what);
> total = name_len + what_len + 3;
>
> p = buf = alloca(total);
> memcpy(p, name, name_len);
> p += name_len;
> *p++ = ' ';
> memcpy(p, what, what_len);
> p += what_len;
> *p++ = ':';
> *p = ' ';
>
> *buf &= ~0x20;
>
> Write(2, buf, total);
> }
>
> be considered obvious or should it rather get an explanation?
> ?
> An ASCII lowercase letter can be turned into the corresponding uppercase
> letter by clearing the sixth bit.
I'm unhappy for two reasons:
the failure mode of alloca is SIGSEGV or some other malfunction and there is
no way to test for it
the *buf &= ~0x20; breaks for UTF8 strings.
Nevermind that the function implicitly references stderr except when it doesn't.
Peter Olson