Skip to content

fix book code: fix strncpy does not NUL terminate filename - #1

Open
Justme0 wants to merge 1 commit into
T-bagwell:book/base_ffmpeg_6.0from
Justme0:book/fix_code_strncpy
Open

fix book code: fix strncpy does not NUL terminate filename#1
Justme0 wants to merge 1 commit into
T-bagwell:book/base_ffmpeg_6.0from
Justme0:book/fix_code_strncpy

Conversation

@Justme0

@Justme0 Justme0 commented Apr 4, 2024

Copy link
Copy Markdown
  • In FFmpegPlayer.cpp, strncpy(playerCtx.filename, m_filePath.c_str(), m_filePath.size()); does not NUL terminate filename. Three solutions: 1) From strncpy(3) example, NUL terminate the result string explicitly. But it's tedious. 2) Use strlcpy(3) but not portable. 3) Use std::string to avoid the pitfall. I prefer the last solution.

    Reference: https://stackoverflow.com/a/1454071/1204713

 - In `FFmpegPlayer.cpp`, `strncpy(playerCtx.filename, m_filePath.c_str(), m_filePath.size());`
   does not NUL terminate filename. Three solutions:
   1) From strncpy(3) example, NUL terminate the result string explicitly. But it's tedious.
   2) Use strlcpy(3) but not portable.
   3) Use std::string to avoid the pitfall.
   I prefer the last solution.

   Reference: https://stackoverflow.com/a/1454071/1204713
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.

1 participant