On 12/23/2011 8:04 AM, JohnF wrote:
> pete<
pfi...@mindspring.com> wrote:
>> JohnF wrote:
>>>
>>> warning: string length '1008' is greater than the
>>> length '509'
>>> static char latexwrapper[16384] =
>>> "\\documentclass[10pt]{article}\n"
>>> "\\usepackage[latin1]{inputenc}\n"
>>> "\\usepackage{amsmath}\n"
>>> "\\usepackage{amsfonts}\n"
>>> "...lots-more-junk...";
>>
>> if latexwrapper is supposed to be constant,
>
> Nope, it contains embedded keywords like %%expression%%
> (always something delimited by %%...%%) that later gets
> substituted with the user's input expression, and various
> other substitutions like font size and similar
> gobbledy-gook. (And, yeah, I make sure the 16384 allocation
> doesn't overflow.)
Replacement in situ? Yukk! Not only does it pose a significant
risk of buffer overflow, but it also means that a string of this kind
is not reusable: Process it once, and all those %%foo%% bits have
vanished. And just to heighten the sense of outrage, the substitution
probably takes quadratic time ...
If you're still interested in staying within the 509-character
limit (thus ensuring that resource-constrained compilers won't choke
on your source code), I'd suggest chopping the big blob of text into
chunks of convenient size. Before processing, you can allocate a big
buffer and strcpy/strcat the little strings into it, then use the big
buffer exactly as you're now using the latexwrapper[] array. (This
solves the reusability problem, by the way, although you still face the
buffer overflow and quadratic time issues.)
Others have mentioned the possibility of reading this block of text
from a file instead of burying it in the program code. Although that
gives up some degree of self-containment, it brings some advantages.
For example, if you decide you'd like 12-point instead of 10-point
titles you can just edit the external file without rebuilding the
program from source -- if you're an end user, you might not even have
access to the source. Don't reject the idea out-of-hand.
--
Eric Sosman
eso...@ieee-dot-org.invalid