Skip to content

Commit

Permalink
using memcpy instead of strncpy to avoid -Werror=stringop-truncation
Browse files Browse the repository at this point in the history
  • Loading branch information
MadVitaliy committed Aug 6, 2024
1 parent da28834 commit 403af99
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions Source/DataStructureAndEncodingDefinition/gdcmElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <limits>
#include <cmath>
#include <cstring>
#include <algorithm>

namespace gdcm_ns
{
Expand Down Expand Up @@ -346,9 +345,6 @@ static int roundat(char *buf, size_t bufLen, unsigned int i, int iexp) {
return 0;
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
#define MIN(a, b) ((a)<(b)?(a):(b))
template < typename Float >
static void x16printf(char *buf, int size, Float f) {
char line[40];
Expand Down Expand Up @@ -413,14 +409,11 @@ static void x16printf(char *buf, int size, Float f) {
for(j=0; j< -1 - iexp; j++) {
buf[j+1] = '0';
}
long unsigned int copy_len = size + 1 + iexp;
mant[MIN(copy_len, sizeof(line) - 1)] = '\n';
strncpy(buf - iexp, mant, copy_len);
buf[size] = '\n';
memcpy(buf - iexp, mant, size + 1 + iexp);
buf[size] = 0;
clean(buf);
}
}
#pragma GCC diagnostic pop
#if defined(_MSC_VER) && (_MSC_VER < 1900)
#undef snprintf
#endif
Expand Down

0 comments on commit 403af99

Please sign in to comment.