Archived issue #0029344
Foundation Classes, TCollection_AsciiString - replace confusing strncpy with memcpy
Description
TCollection_AsciiString implementation uses strncpy + strlen combination which does not make sense, because after strlen the length of the string is already determined and plain memcpy can be called instead.
Steps to reproduce
N/A
Public activity
11 archived notes
Participants are labeled by their role within this record.
Branch [archived branch] has been created by Author.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Fri Nov 24 18:37:01 2017 +0300
0029344: Foundation Classes, TCollection_AsciiString - replace confusing strncpy with memcpy
strncpy usage within TCollection_AsciiString has been replaced by memcpy
where string lenght has been already determined.
TCollection_AsciiString(const char* , int ) and TCollection_AsciiString::SetValue()
have been modified to throw exception on attempt to define invalid length of the string.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Fri Nov 24 18:37:01 2017 +0300
0029344: Foundation Classes, TCollection_AsciiString - replace confusing strncpy with memcpy
strncpy usage within TCollection_AsciiString has been replaced by memcpy
where string lenght has been already determined.
TCollection_AsciiString(const char* , int ) and TCollection_AsciiString::SetValue()
have been modified to throw exception on attempt to define invalid length of the string.
Branch [archived branch] has been updated by Author.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Fri Nov 24 22:00:08 2017 +0300
# fix regressions
[revision removed]
Detailed log of new commits:
Author: Author
Date: Fri Nov 24 22:00:08 2017 +0300
# fix regressions
Branch [archived branch] has been created by Author.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Fri Nov 24 18:37:01 2017 +0300
0029344: Foundation Classes, TCollection_AsciiString - replace confusing strncpy with memcpy
strncpy() usage within TCollection_AsciiString has been replaced by memcpy()
where string length has been already determined.
TCollection_AsciiString::SetValue() now throws exception
on attempt to set '\0' - TCollection_AsciiString::Trunc() should be used instead.
TCollection_AsciiString(const char* , int ) has been modified to properly set string length
in case of NULL-terminator appeared earlier then specified length.
Interface_LineBuffer has been revised for using NCollection_Array1 instead of TCollection_AsciiString
to avoid misusing TCollection_AsciiString interface.
[revision removed]
Detailed log of new commits:
Author: Author
Date: Fri Nov 24 18:37:01 2017 +0300
0029344: Foundation Classes, TCollection_AsciiString - replace confusing strncpy with memcpy
strncpy() usage within TCollection_AsciiString has been replaced by memcpy()
where string length has been already determined.
TCollection_AsciiString::SetValue() now throws exception
on attempt to set '\0' - TCollection_AsciiString::Trunc() should be used instead.
TCollection_AsciiString(const char* , int ) has been modified to properly set string length
in case of NULL-terminator appeared earlier then specified length.
Interface_LineBuffer has been revised for using NCollection_Array1 instead of TCollection_AsciiString
to avoid misusing TCollection_AsciiString interface.
Branch [archived branch] has been updated forcibly by Author.
[revision removed]
[revision removed]
Reviewed, please integrate
Actually I have a doubt whether having null symbol in the middle of the string should really be prohibited...
> Actually I have a doubt whether having null symbol in the middle
> of the string should really be prohibited..
This is misconception - TCollection_AsciiString is supposed to know the length of the string to behave in deterministic way.
Although one would say that constant string class should not have method SetValue() at all.
Considering an allocation of buffer of greater size then actual string length, another mechanism might be considered - e.g. std::string has two properties: actual length and capacity.
> of the string should really be prohibited..
This is misconception - TCollection_AsciiString is supposed to know the length of the string to behave in deterministic way.
Although one would say that constant string class should not have method SetValue() at all.
Considering an allocation of buffer of greater size then actual string length, another mechanism might be considered - e.g. std::string has two properties: actual length and capacity.
Combination -
OCCT branch : [archived branch] SHA - [revision removed]
Products branch : [archived branch] SHA - [revision removed]
was compiled on Linux, MacOS and Windows platforms and tested on optimize mode.
Number of compiler warnings:
No new/fixed warnings
Regressions/Differences/Improvements:
No regressions/differences
CPU differences:
Debian70-64:
OCCT
Total CPU difference: 20052.220000000558 / 19837.270000000357 [+1.08%]
Products
Total CPU difference: 7995.2600000000875 / 8039.350000000084 [-0.55%]
Windows-64-VC10:
OCCT
Total CPU difference: 17873.174970898603 / 17832.614710898575 [+0.23%]
Products
Total CPU difference: 8036.500715699982 / 8019.621407499985 [+0.21%]
Image differences :
No differences that require special attention
Memory differences :
No differences that require special attention
OCCT branch : [archived branch] SHA - [revision removed]
Products branch : [archived branch] SHA - [revision removed]
was compiled on Linux, MacOS and Windows platforms and tested on optimize mode.
Number of compiler warnings:
No new/fixed warnings
Regressions/Differences/Improvements:
No regressions/differences
CPU differences:
Debian70-64:
OCCT
Total CPU difference: 20052.220000000558 / 19837.270000000357 [+1.08%]
Products
Total CPU difference: 7995.2600000000875 / 8039.350000000084 [-0.55%]
Windows-64-VC10:
OCCT
Total CPU difference: 17873.174970898603 / 17832.614710898575 [+0.23%]
Products
Total CPU difference: 8036.500715699982 / 8019.621407499985 [+0.21%]
Image differences :
No differences that require special attention
Memory differences :
No differences that require special attention
Branch [archived branch] has been deleted by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been deleted by Author.
[revision removed]
[revision removed]
Related records