Skip to content

Commit 52181e1

Browse files
check for snprintf return value for full fix to warning
1 parent b53b8c1 commit 52181e1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/PyBytesProxyHandler.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,17 @@ static bool array_valueOf(JSContext *cx, unsigned argc, JS::Value *vp) {
4343
const size_t STRING_LENGTH = byteLength + numberOfDigits;
4444
JS::Latin1Char *buffer = (JS::Latin1Char *)malloc(sizeof(JS::Latin1Char) * STRING_LENGTH);
4545

46-
snprintf((char *)&buffer[0], 3 + 1, "%hu", data[0]);
46+
if (snprintf((char *)&buffer[0], 3 + 1, "%hu", data[0]) < 0) {
47+
return false;
48+
}
4749
size_t charIndex = data[0] < 10 ? 1 : data[0] < 100 ? 2 : 3;
4850

4951
for (size_t dataIndex = 1; dataIndex < byteLength; dataIndex++) {
5052
buffer[charIndex] = ',';
5153
charIndex++;
52-
snprintf((char *)&buffer[charIndex], 3 + 1, "%hu", data[dataIndex]);
54+
if (snprintf((char *)&buffer[charIndex], 3 + 1, "%hu", data[dataIndex]) < 0) {
55+
return false;
56+
}
5357
charIndex += data[dataIndex] < 10 ? 1 : data[dataIndex] < 100 ? 2 : 3;
5458
}
5559

0 commit comments

Comments
 (0)