Re: The String class for 0.60 does not null terminate strings.
"Gary Setter" <[email protected]>
| Newsgroups | gmane.comp.gnu.aspell.devel |
|---|---|
| Message-ID | <001e01c4a496$758de660$24144a0c@pavilion> |
----- Original Message ----- From: "Kevin Atkinson" <[email protected]> To: "Gary Setter" <[email protected]> Cc: <[email protected]> Sent: Sunday, September 26, 2004 9:52 PM Subject: Re: [aspell-devel] The String class for 0.60 does not null terminate strings. > On Sun, 26 Sep 2004, Gary Setter wrote: > > > I'm doing a Win32 port. I just got it to compile and I'm seeing > > how things work. Right away I see that the String class does not > > null terminate. > > Can you be more specific. The String class does not always null terminate > but it does when needed. The version that I downloaded has a write date of 24-Jun-04 11:07pm The c'tor from a const char * is String(const char * s) {assign_only(s);} assign only is void assign_only(const char * b) { if (b && *b) assign_only_nonnull(b, strlen(b)); else zero(); } assign_only_nonnull is void assign_only_nonnull(const char * b, unsigned size) { begin_ = (char *)malloc(size + 1); memmove(begin_, b, size); end_ = begin_ + size; storage_end_ = end_ + 1; } If you do something like String s("a"); You will call assign_only_nonnull with b= "a\0" and size = 1. The memmove will only copy one character ( the 'a' ) to begin_[0], begin_[1] is not initialized. That is just one example. Do you want to see my rendition?