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

MNT: constant string arrays instead of pointers in C#28985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
DimitriPapadopoulos wants to merge3 commits intonumpy:main
base:main
Choose a base branch
Loading
fromDimitriPapadopoulos:const_char

Conversation

DimitriPapadopoulos
Copy link
Contributor

@DimitriPapadopoulosDimitriPapadopoulos commentedMay 16, 2025
edited
Loading

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);      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
char *p = buf;
memcpy(p, prefix, plen);
p += plen;
memcpy(p, type_name, nlen);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

why this change?

Copy link
ContributorAuthor

@DimitriPapadopoulosDimitriPapadopoulosMay 16, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

See the comment in the relevant commit:

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);      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~

The previous code had already been usingmemcpy() instead ofstrncpy() to avoid a similar warning. The new code extends the logic tostrncat(). In any case, the code should be consistent, and use only one set of methods:

  • Usestrcpy()/strcat() all along, relying on the trailing NUL to find the characters to copy. This would avoid compiler warnings. I know these functions feel less secure, but in this case they are not since we know for sure the destinationbuf is large enough.
  • Usestrncpy()/strncat() all along, looking for a trailing NUL while copying, but omitting writing the trailing NUL in the destinationbuf, since it is already initialised byPyMem_RawCalloc(). This results in the above compiler warning, because the trailing NUL is omitted.
  • Usememcpy() all along, relying on the already calculated length of the strings. That should be the most efficient option and avoids compiler warnings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sounds good 👍

p += plen;
memcpy(p, type_name, nlen);
p += nlen;
memcpy(p, suffix, slen);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

this too

@DimitriPapadopoulosDimitriPapadopoulos marked this pull request as ready for reviewMay 16, 2025 12:52
@ngoldbaum
Copy link
Member

I wonder if we could get clang-tidy to lint stuff like this.

@DimitriPapadopoulos
Copy link
ContributorAuthor

I think Linux'scheckpatch.pl could have caught some of these issues, I don't have experience withclang-tidy but wasn't able to find relevant checks.

ngoldbaum reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ngoldbaumngoldbaumngoldbaum approved these changes

Assignees
No one assigned
Labels
03 - Maintenance09 - Backport-CandidatePRs tagged should be backported
Projects
None yet
Milestone
2.3.0 release
Development

Successfully merging this pull request may close these issues.

3 participants
@DimitriPapadopoulos@ngoldbaum@charris

[8]ページ先頭

©2009-2025 Movatter.jp