Re: small problem in lyxstring constructor
"Lars" == Lars Gullik Bjønnes [EMAIL PROTECTED] writes: Lars But we should check the standard, and see if a '\0' teminated Lars string is required, and wat values of n is allowed. You are right. The standard says nothing about the string being 0-terminated (or using traits to get the length) in this case. I removed the loop. JMarc
Re: small problem in lyxstring constructor
> "Lars" == Lars Gullik Bjønnes <[EMAIL PROTECTED]> writes: Lars> But we should check the standard, and see if a '\0' teminated Lars> string is required, and wat values of n is allowed. You are right. The standard says nothing about the string being 0-terminated (or using traits to get the length) in this case. I removed the loop. JMarc
Re: small problem in lyxstring constructor
I have anoter proposal: Since there is a n argument, we can expect this to be meeningful, so: I think so, too. 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. 'n' is the authority in question here. You can store and retrieve as many '\0' char in a std::string. They are 'ordinary' characters there. Andre' -- Andre' Poenitz [EMAIL PROTECTED]
Re: small problem in lyxstring constructor
> I have anoter proposal: Since there is a n argument, we can expect > this to be meeningful, so: I think so, too. > 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 = _rep; > } > } > > But we should check the standard, and see if a '\0' teminated string > is required, and wat values of n is allowed. 'n' is the authority in question here. You can store and retrieve as many '\0' char in a std::string. They are 'ordinary' characters there. Andre' -- Andre' Poenitz [EMAIL PROTECTED]
Re: small problem in lyxstring constructor
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
Re: small problem in lyxstring constructor
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 = _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 = _rep; } } But we should check the standard, and see if a '\0' teminated string is required, and wat values of n is allowed. Lgb
small problem in lyxstring constructor
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? JMarc
small problem in lyxstring constructor
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 = _rep; } } Lars, before changing this somewhat sensitive code, could you comment on what is the right fix? JMarc