Possible bug in OFString::copy()

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
oxymoron
Posts: 17
Joined: Wed, 2006-08-02, 16:40

Possible bug in OFString::copy()

#1 Post by oxymoron »

Imay have come across a little bug in the implementation of the OFString::copy() in version 3.6.0 (ofstring.cc line 434)
The referred method didn´t work as expected and when I traced it found that the copyMem function was copying the original string and not the desired substring.

[code]
size_t
OFString::copy (char* s, size_t n, size_t pos) const
{
OFString sub(this->substr(pos, n));
// String length *including* the trailing EOS
const size_t result = sub.size() + 1;

// The string could have NULL bytes so no strncpy()
OFBitmanipTemplate<char>::copyMem(this->theCString, s, result);
return result;
}

should be:

size_t
OFString::copy (char* s, size_t n, size_t pos) const
{
OFString sub(this->substr(pos, n));
// String length *including* the trailing EOS
const size_t result = sub.size() + 1;

// The string could have NULL bytes so no strncpy()
OFBitmanipTemplate<char>::copyMem(sub, s, result); // copy the substring to s
return result;
}

[/code]

oxymoron
Posts: 17
Joined: Wed, 2006-08-02, 16:40

Re: Possible bug in OFString::copy()

#2 Post by oxymoron »

sorry, the line shoud have been

OFBitmanipTemplate<char>::copyMem(sub->theCString, s, result); // copy the substring to s

J. Riesmeier
DCMTK Developer
Posts: 2506
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Possible bug in OFString::copy()

#3 Post by J. Riesmeier »

Thank you for the report. I guess you are right. This pretty much looks like a bug (that has been introduced with adding support for 0 bytes within a character string some time ago). We will fix this and let you know ...

Uli Schlachter
DCMTK Developer
Posts: 120
Joined: Thu, 2009-11-26, 08:15

Re: Possible bug in OFString::copy()

#4 Post by Uli Schlachter »

Again, thank you for the report. This was now fixed in the latest development version. Also, the return value of copyMem() was wrong and some more unit tests were added. For more information, see:
http://git.dcmtk.org/web?p=dcmtk.git;a= ... 30ba4045fa

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest