[m-users.] string_writer / stream and writing strings with %s in them

Zoltan Somogyi zoltan.somogyi at runbox.com
Sun Feb 13 09:05:24 AEDT 2022


2022-02-13 03:20 GMT+11:00 "Sean Charles (emacstheviking)" <objitsu at gmail.com>:
> Which works but....as I tested my way through, the problem is compounded by the recursive nature of the rendering stage, resulting in strings like this:
> 
>    printf("Hello %%%%%s", "World");

If  by "recursive nature" you mean that you are applying this "double the %s"
transformation to its own output, then that fact itself would seem to be the problem.

> caused by each successive handler

Each successive handler of what?

> I wondered what strategy the Mercury compiler uses as it must have addressed the same issue at some point? I've tried reading the code to no avail! 

I think you are looking for something that isn't there.

The Mercury compiler handles quoting twice. During parsing, it removes
quoting from its input, according to the rules of Mercury, since its input is
Mercury code. Then, during the final stage of code generation,
it adds quoting as necessary, according to the rules of either C,
C# or Java, depending on what the target language is.

If you have a stack of "handlers" of whatever kind that each add quoting,
you have to ask yourself: what rules govern each instance of that process?
In other words, what language's strings do they process?

At the very least, you need to make a distinction between strings
that have already been quoted and strings that have not yet been
through that process. This is similar to taint analysis. Taint analysis ensures
that every input to the program is sanitized; you want to ensure every string
you output is properly quoted. You also want to ensure no string goes
through quoting more than once, but keeping track of which strings
have been through quoting and which haven't been should make that
easy.

Zoltan.


More information about the users mailing list