Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd171d09

Browse files
MNT: alternative handling of trailing null character
Trying to avoid this compiler warning: ../numpy/_core/src/multiarray/stringdtype/casts.cpp:860:12: warning: 'char* strncat(char*, const char*, size_t)' specified bound 15 equals source length [-Wstringop-overflow=] 860 | strncat(buf, suffix, slen); | ~~~~~~~^~~~~~~~~~~~~~~~~~~
1 parent60fccd5 commitd171d09

File tree

1 file changed

+10
-7
lines changed
  • numpy/_core/src/multiarray/stringdtype

1 file changed

+10
-7
lines changed

‎numpy/_core/src/multiarray/stringdtype/casts.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -833,10 +833,11 @@ make_s2type_name(NPY_TYPES typenum) {
833833
returnNULL;
834834
}
835835

836-
// memcpy instead of strcpy to avoid stringop-truncation warning, since
837-
// we are not including the trailing null character
836+
// memcpy instead of strcpy/strncat to avoid stringop-truncation warning,
837+
//sincewe are not including the trailing null character
838838
memcpy(buf, prefix, plen);
839-
strncat(buf, type_name, nlen);
839+
buf += plen;
840+
memcpy(buf, type_name, nlen);
840841
return buf;
841842
}
842843

@@ -853,11 +854,13 @@ make_type2s_name(NPY_TYPES typenum) {
853854

854855
char *buf = (char *)PyMem_RawCalloc(sizeof(char), plen + nlen + slen +1);
855856

856-
// memcpy instead of strcpy to avoid stringop-truncation warning, since
857-
// we are not including the trailing null character
857+
// memcpy instead of strcpy/strncat to avoid stringop-truncation warning,
858+
//sincewe are not including the trailing null character
858859
memcpy(buf, prefix, plen);
859-
strncat(buf, type_name, nlen);
860-
strncat(buf, suffix, slen);
860+
buf += plen;
861+
memcpy(buf, type_name, nlen);
862+
buf += nlen;
863+
memcpy(buf, suffix, slen);
861864
return buf;
862865
}
863866

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp