Skip to content

Commit b53b8c1

Browse files
snprintf warning fix
1 parent ce0394d commit b53b8c1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/PyBytesProxyHandler.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ static bool array_valueOf(JSContext *cx, unsigned argc, JS::Value *vp) {
3939
for (size_t i = 0; i < byteLength; i++) {
4040
numberOfDigits += data[i] < 10 ? 1 : data[i] < 100 ? 2 : 3;
4141
}
42+
4243
const size_t STRING_LENGTH = byteLength + numberOfDigits;
4344
JS::Latin1Char *buffer = (JS::Latin1Char *)malloc(sizeof(JS::Latin1Char) * STRING_LENGTH);
4445

45-
size_t charIndex = 0;
46-
snprintf((char *)&buffer[charIndex], 4, "%d", data[0]);
47-
charIndex += data[0] < 10 ? 1 : data[0] < 100 ? 2 : 3;
46+
snprintf((char *)&buffer[0], 3 + 1, "%hu", data[0]);
47+
size_t charIndex = data[0] < 10 ? 1 : data[0] < 100 ? 2 : 3;
4848

4949
for (size_t dataIndex = 1; dataIndex < byteLength; dataIndex++) {
5050
buffer[charIndex] = ',';
5151
charIndex++;
52-
snprintf((char *)&buffer[charIndex], 4, "%d", data[dataIndex]);
52+
snprintf((char *)&buffer[charIndex], 3 + 1, "%hu", data[dataIndex]);
5353
charIndex += data[dataIndex] < 10 ? 1 : data[dataIndex] < 100 ? 2 : 3;
5454
}
5555

5656
JS::UniqueLatin1Chars str(buffer);
57-
args.rval().setString(JS_NewLatin1String(cx, std::move(str), STRING_LENGTH - 1)); // don't include null byte
57+
args.rval().setString(JS_NewLatin1String(cx, std::move(str), STRING_LENGTH - 1)); // don't include the null terminating byte
5858
return true;
5959
}
6060

0 commit comments

Comments
 (0)