From dca33f49affdd5318973fd16b2e4798bb91e8c7f Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Fri, 9 Apr 2010 09:48:22 +0000 Subject: [PATCH] Don't initialize our string twice in OFString::reserve(). --- CHANGES.355 | 3 +++ ofstd/libsrc/ofstring.cc | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGES.355 b/CHANGES.355 index 0c59f59e..63ac8e4e 100644 --- a/CHANGES.355 +++ b/CHANGES.355 @@ -6,6 +6,9 @@ Changes between releases are documented here. - Fix some warnings abort variables shadowing other variables. Affects: oflog/include/dcmtk/oflog/spi/logevent.h +- Don't initialize our string twice in OFString::reserve(). + Affects: ofstd/libsrc/ofstring.cc + **** Changes from 2010.03.31 (onken) - Make configure script reflect the recent changes to configure.in regarding diff --git a/ofstd/libsrc/ofstring.cc b/ofstd/libsrc/ofstring.cc index fb681ded..60dd07a8 100644 --- a/ofstd/libsrc/ofstring.cc +++ b/ofstd/libsrc/ofstring.cc @@ -1,6 +1,6 @@ /* * - * Copyright (C) 1997-2009, OFFIS + * Copyright (C) 1997-2010, OFFIS * * This software and supporting documentation were developed by * @@ -22,8 +22,8 @@ * Purpose: A simple string class * * Last Update: $Author: uli $ - * Update Date: $Date: 2010-01-05 14:05:34 $ - * CVS/RCS Revision: $Revision: 1.26 $ + * Update Date: $Date: 2010-04-09 09:48:23 $ + * CVS/RCS Revision: $Revision: 1.27 $ * Status: $State: Exp $ * * CVS/RCS Log at end of file @@ -391,17 +391,15 @@ OFString::reserve (size_t res_arg) if (this->theCapacity < res_arg) { char* newstr = new char[res_arg]; if (newstr) { - for (size_t i = 0; i < res_arg; i++) { - newstr[i] = '\0'; - } + size_t usedSpace = 0; this->theCapacity = res_arg - 1; /* not the eos */ if (this->size() > 0) { - const size_t len = size() + 1; /* including the eos */ + const size_t len = size(); // copyMem() because theCString could have null bytes OFBitmanipTemplate::copyMem(this->theCString, newstr, len); - } else { - newstr[0] = '\0'; + usedSpace = len; } + OFBitmanipTemplate::zeroMem(newstr + usedSpace, res_arg - usedSpace); char* oldstr = this->theCString; this->theCString = newstr; delete[] oldstr; @@ -1051,6 +1049,9 @@ int ofstring_cc_dummy_to_keep_linker_from_moaning = 0; /* ** CVS/RCS Log: ** $Log: ofstring.cc,v $ +** Revision 1.27 2010-04-09 09:48:23 uli +** Don't initialize our string twice in OFString::reserve(). +** ** Revision 1.26 2010-01-05 14:05:34 uli ** Made sure OFString always null-terminates its C-Strings. **