Jean-Marc Lasgouttes <[EMAIL PROTECTED]> writes:
| While running purify on lyx, I find plenty of uninitialized memory
| read coming from lyxstring constructor
| lyxstring::lyxstring(value_type const * s, size_type n)
|
| The problem is that the constructor uses at some place min(n, strlen(s))
| although s may not be null terminated. I propose to rewrite the
| constructor as follows:
|
| lyxstring::lyxstring(value_type const * s, size_type n)
| {
| Assert(s && n < npos); // STD!
| static Srep empty_rep(0, "");
| if (*s && n) { // s is not empty string and n > 0
| size_type l = 0;
| while (l < n && s[l])
| l++;
| rep = new Srep(l, s);
| // rep = new Srep(min(strlen(s),n), s);
| } else {
| ++empty_rep.ref;
| rep = &empty_rep;
| }
| }
|
|
| Lars, before changing this somewhat sensitive code, could you comment
| on what is the right fix?
I have anoter proposal: Since there is a n argument, we can expect
this to be meeningful, so:
lyxstring::lyxstring(value_type const * s, size_type n)
{
Assert(s && n < npos); // STD!
static Srep empty_rep(0, "");
if (*s && n) { // s is not empty string and n > 0
rep = new Srep(n, s);
} else {
++empty_rep.ref;
rep = &empty_rep;
}
}
But we should check the standard, and see if a '\0' teminated string
is required, and wat values of n is allowed.
Lgb