mirror of
https://github.com/trabucayre/openFPGALoader.git
synced 2026-08-30 18:02:38 +02:00
Fix snprintf usage
Some code used snprintf on std::string objects. This caused unexpected behaviour where '\0' was printed to the output file. This commit adds intermediate char* buffer which is later used to initialize std::string. This string is later resized to the correct expected length. Signed-off-by: Maciej Dudek <[email protected]>
This commit is contained in:
+18
-5
@@ -119,13 +119,26 @@ int DFUFileParser::parseHeader()
|
||||
{"idVendor", string(7, ' ')}, {"idProduct", string(7, ' ')},
|
||||
{"bcdDevice", string(7, ' ')}};
|
||||
|
||||
snprintf(&_hdr["dwCRC"][0], 11, "0x%08x", _dwCRC);
|
||||
|
||||
char __buf[16];
|
||||
int __buf_valid_bytes;
|
||||
__buf_valid_bytes = snprintf(__buf, 11, "0x%08x", _dwCRC);
|
||||
_hdr["dwCRC"] = string(__buf, __buf_valid_bytes);
|
||||
_hdr["dwCRC"].resize(11, ' ');
|
||||
_hdr["bLength"] = to_string(_bLength);
|
||||
_hdr["ucDfuSignature"] = ucDfuSignature;
|
||||
snprintf(&_hdr["bcdDFU"][0], 7, "0x%04x", _bcdDFU);
|
||||
snprintf(&_hdr["idVendor"][0], 7, "0x%04x", _idVendor);
|
||||
snprintf(&_hdr["idProduct"][0], 7, "0x%04x", _idProduct);
|
||||
snprintf(&_hdr["bcdDevice"][0], 7, "0X%04x", _bcdDevice);
|
||||
__buf_valid_bytes = snprintf(__buf, 7, "0x%04x", _bcdDFU);
|
||||
_hdr["bcdDFU"] = string(__buf, __buf_valid_bytes);
|
||||
_hdr["bcdDFU"].resize(7, ' ');
|
||||
__buf_valid_bytes = snprintf(__buf, 7, "0x%04x", _idVendor);
|
||||
_hdr["idVendor"] = string(__buf, __buf_valid_bytes);
|
||||
_hdr["idVendor"].resize(7, ' ');
|
||||
__buf_valid_bytes = snprintf(__buf, 7, "0x%04x", _idProduct);
|
||||
_hdr["idProduct"] = string(__buf, __buf_valid_bytes);
|
||||
_hdr["idProduct"].resize(7, ' ');
|
||||
__buf_valid_bytes = snprintf(__buf, 7, "0x%04x", _bcdDevice);
|
||||
_hdr["bcdDevice"] = string(__buf, __buf_valid_bytes);
|
||||
_hdr["bcdDevice"].resize(7, ' ');
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user