On Wed, Apr 10, 2002 at 06:29:30PM -0400, Roman Hunt wrote:
> Hey guys:
>   Here is what I have so far of the string_nprintf function.  As of now it
>  only handles C string backslash escape sequences and regular chars
> from the format string.  My primary concern is whether I am using

> +        else if (*(format++) == '\\') {
> +            if (sprintf_emu)
> +                ++grow_total;
> +            if (*format == 'n') {
> +                c = '\n';
> +                if (sprintf_emu || (len-- != 0)) {
> +                    b_trans = string_make(interpreter, cp, 1, NULL,
> +                                          BUFFER_immobile_FLAG, NULL);
> +                    (void)string_concat(interpreter, temp_str, b_trans,
> +                                        transcode);
> +                    string_destroy(b_trans);
> +                }
> +            }


I don't think that you should be doing \ escape processing in *printf.
C doesn't do \ escape processing in *printf - the \ escape processing is
done by the preprocessor when it makes literal strings while compiling the
program.

If all the \ escape processing happened inside *printf then my test program:

#include <stdio.h>

int main () {
    printf ("Hello World\n\0This would get through\n");
    printf ("Hello Again\n%c0 byte in output\n", '\0');
    return 0;
}

would produce 4 lines of output, when actually it produces three:

Hello World
Hello Again
0 byte in output

(0 byte doesn't display in my xterm, and I'm not going to inject it into this
message using my mailer, because somebody's mailer out there will barf on it)

Nicholas Clark
-- 
Even better than the real thing:        http://nms-cgi.sourceforge.net/

Reply via email to