Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error: strncpy truncates string #31

Open
CyanoKobalamyne opened this issue Mar 29, 2021 · 5 comments
Open

Compilation error: strncpy truncates string #31

CyanoKobalamyne opened this issue Mar 29, 2021 · 5 comments

Comments

@CyanoKobalamyne
Copy link

I get the following error during compilation:

benchmarks/tpcc_txn.cpp: In member function ‘RC tpcc_txn_man::run_payment(tpcc_query*)’:
benchmarks/tpcc_txn.cpp:211:9: error: ‘char* strncpy(char*, const char*, size_t)’ output may be truncated copying 10 bytes from a string of length 10 [-Werror=stringop-truncation]
  211 |  strncpy(h_data, w_name, 10);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~

I think that this is due to the fact that w_name is declared as 11 characters long (with the last character likely being NULL), but only the first 10 are copied here. Is this intended? It seems to me that, if the character array is not null-terminated, that can cause problems for the strlen call afterwards, even if it's not needed in the end because multiple strings are being joined.

@Chen-yu-Zheng
Copy link

how to solve it?

@CyanoKobalamyne
Copy link
Author

Changing the length in the strncpy call to 11 should work.

@wulinze
Copy link

wulinze commented Sep 29, 2021

It didn't work, how to solve this issue for you.Please give a solution for this issue. This is completely a bug.

@CyanoKobalamyne
Copy link
Author

What do you mean it didn't work? What error are you getting? Do the declared size of the array and the number in the call match?

@duanyang25
Copy link

See #38,

Just change one line of the Makefile under the root folder.

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 a pull request may close this issue.

4 participants