Skip to content

Refactor to satisfy compiler on string manipulation#506

Merged
aurelienpierre merged 1 commit intoaurelienpierreeng:masterfrom
Jiyone:better_str
Apr 9, 2025
Merged

Refactor to satisfy compiler on string manipulation#506
aurelienpierre merged 1 commit intoaurelienpierreeng:masterfrom
Jiyone:better_str

Conversation

@Jiyone
Copy link
Copy Markdown
Collaborator

@Jiyone Jiyone commented Apr 7, 2025

  • filename_size renamed to filename_len because size supposes it includes the null terminating char (as sizeof() would do), but strlen() doesn't.

  • PATH_MAX includes null terminating char, so we need to see if the string length will be greater or equal.

  • Adding \0 at the end of strings we are initializing is redundant.

  • g_snprintf() lets us manipulate string securely, without overflow and always terminate with \0 even if the source is longer than the target.

- "filename_size" renamed to "filename_len" because "size" supposes it includes
the null terminating char (as sizeof() would do), but strlen() doesn't.

- PATH_MAX includes null terminating char, so we need to compare >=.

- Adding \0 at the end of a string is redundant.

- g_snprintf() lets us manipulate string without overflow and always terminate
  with \0 even if the source is longer than the target.
@aurelienpierre
Copy link
Copy Markdown
Collaborator

Thanks !

@aurelienpierre aurelienpierre merged commit 4689a5d into aurelienpierreeng:master Apr 9, 2025
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 9, 2025

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants