Skip to content

Commit

Permalink
Don't initialize our string twice in OFString::reserve().
Browse files Browse the repository at this point in the history
  • Loading branch information
Uli Schlachter committed Apr 9, 2010
1 parent 2da5345 commit dca33f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGES.355
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions ofstd/libsrc/ofstring.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 1997-2009, OFFIS
* Copyright (C) 1997-2010, OFFIS
*
* This software and supporting documentation were developed by
*
Expand All @@ -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
Expand Down Expand Up @@ -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<char>::copyMem(this->theCString, newstr, len);
} else {
newstr[0] = '\0';
usedSpace = len;
}
OFBitmanipTemplate<char>::zeroMem(newstr + usedSpace, res_arg - usedSpace);
char* oldstr = this->theCString;
this->theCString = newstr;
delete[] oldstr;
Expand Down Expand Up @@ -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.
**
Expand Down

0 comments on commit dca33f4

Please sign in to comment.