jacob navia said:
2GB strings are the most you can get under the windows schema in 32 bits.
Ok. Does your compiler know that?
Assigning an arbitrary size_t value to an object of type int, if both
types are 32 bits, could potentially overflow. Your compiler
apparently doesn't issue a warning in that case. Is it because it
knows that the value returned by strlen() can't exceed INT_MAX (if so,
well done, especially since it seems to be smart enough not to make
that assumption on a 64-bit system), or is it because it doesn't issue
a warning when both types are the same size?
For example:
size_t s = func(-1);
/* Assume func() takes a size_t argument and returns it.
Assume func() is defined in another translation unit,
so the compiler can't analyze its definition. In other
words, 's' is initialized to SIZE_MAX, but the compiler
can't make any assumptions about its value. */
signed char c = s;
/* Presumably this produces a warning. */
int i = s;
/* This is a potential overflow. Does this produce
a warning? Should it? */
If your compiler warns about the initialization of 'c' but not about
the initialization of 'i', then IMHO it's being inconsistent. This
doesn't address your original question, but it's related.
[...]
There isn't any string longer than a few K in this program!
Of course is a potential bug, but it is practically impossible!
You know that, and I know that, but what matters is what the compiler
knows.
Is it conceivable that a bug in the program and/or some unexpected
input could cause it to create a string longer than 2GB?
You asked how to suppress the bogus warnings without losing any valid
warnings. To do that, your compiler, or some other tool, has to be
able to tell the difference. Telling me that none of the strings are
longer than 2GB doesn't address that concern, unless you can convey
that knowledge to the compiler.