# HG changeset patch # User John W. Eaton # Date 1260425014 18000 # Node ID 7cd2e1b372e577e23b44ced03336969ce1815cb0 # Parent d64d15e12e6bfdbcb030b296dc8f805bd549918e allow scanf to store ASCII NUL values diff -r d64d15e12e6b -r 7cd2e1b372e5 src/ChangeLog --- a/src/ChangeLog Wed Dec 09 15:49:38 2009 -0500 +++ b/src/ChangeLog Thu Dec 10 01:03:34 2009 -0500 @@ -1,3 +1,9 @@ +2009-12-10 John W. Eaton + + * oct-stream.cc (BEGIN_C_CONVERSION, BEGIN_S_CONVERSION): + Store characters directly in appropriately sized std::string object. + (FINISH_CHARACTER_CONVERSION): Do store ASCII NUL values. + 2009-12-09 John W. Eaton * DLD-FUNCTIONS/fltk_backend.cc: Style fixes. diff -r d64d15e12e6b -r 7cd2e1b372e5 src/oct-stream.cc --- a/src/oct-stream.cc Wed Dec 09 15:49:38 2009 -0500 +++ b/src/oct-stream.cc Thu Dec 10 01:03:34 2009 -0500 @@ -1555,22 +1555,16 @@ \ int width = elt->width ? elt->width : 1; \ \ - char *tbuf = new char[width + 1]; \ + std::string tmp (width, '\0'); \ \ int c = EOF; \ int n = 0; \ \ while (is && n < width && (c = is.get ()) != EOF) \ - tbuf[n++] = static_cast (c); \ - \ - tbuf[n] = '\0'; \ + tmp[n++] = static_cast (c); \ \ if (n > 0 && c == EOF) \ - is.clear (); \ - \ - std::string tmp = tbuf; \ - \ - delete [] tbuf + is.clear () // For a `%s' format, skip initial whitespace and then read until the // next whitespace character or until WIDTH characters have been read. @@ -1583,7 +1577,7 @@ { \ if (width) \ { \ - char *tbuf = new char [width+1]; \ + std::string tmp (width, '\0'); \ \ int c = EOF; \ \ @@ -1593,7 +1587,7 @@ { \ if (! isspace (c)) \ { \ - tbuf[n++] = static_cast (c); \ + tmp[n++] = static_cast (c); \ break; \ } \ } \ @@ -1606,17 +1600,13 @@ break; \ } \ else \ - tbuf[n++] = static_cast (c); \ + tmp[n++] = static_cast (c); \ } \ \ - tbuf[n] = '\0'; \ - \ if (n > 0 && c == EOF) \ is.clear (); \ \ - tmp = tbuf; \ - \ - delete [] tbuf; \ + tmp.resize (n); \ } \ else \ { \ @@ -1680,7 +1670,7 @@ { \ conversion_count++; \ \ - while (i < width && tmp[i] != '\0') \ + while (i < width) \ { \ if (data_index == max_size) \ { \