Skip to content

Compilation error: strncpy truncates string #31

@CyanoKobalamyne

Description

@CyanoKobalamyne

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions