Skip to content

Commit 736495a

Browse files
authored
ref: convert an sprintf call to snprintf (#2866)
1 parent fcde045 commit 736495a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Convert one of the two remaining usages of `sprintf` to `snprintf` (#2866)
8+
39
## 8.7.2
410

511
### Fixed

Sources/SentryCrash/Recording/Tools/SentryCrashJSONCodec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ sentrycrashjson_addUIntegerElement(
343343
int result = sentrycrashjson_beginElement(context, name);
344344
unlikely_if(result != SentryCrashJSON_OK) { return result; }
345345
char buff[30];
346-
sprintf(buff, "%" PRIu64, value);
346+
snprintf(buff, sizeof(buff), "%" PRIu64, value);
347347
return addJSONData(context, buff, (int)strlen(buff));
348348
}
349349

Tests/SentryTests/SentryCrash/SentryCrashJSONCodec_Tests.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,4 +1672,20 @@ - (void)testDontCloseLastContainer
16721672
return result;
16731673
}
16741674

1675+
- (void)testFastUIntEncode
1676+
{
1677+
char *expectedJson = "{\"uint\":1234567890}";
1678+
1679+
NSMutableData *encodedData = [NSMutableData data];
1680+
SentryCrashJSONEncodeContext context = { 0 };
1681+
sentrycrashjson_beginEncode(&context, false, addJSONData, (__bridge void *)(encodedData));
1682+
sentrycrashjson_beginObject(&context, NULL);
1683+
sentrycrashjson_addUIntegerElement(&context, "uint", 1234567890);
1684+
sentrycrashjson_endContainer(&context);
1685+
sentrycrashjson_endEncode(&context);
1686+
[encodedData appendBytes:"\0" length:1];
1687+
1688+
[self expectEquivalentJSON:encodedData.bytes toJSON:expectedJson];
1689+
}
1690+
16751691
@end

0 commit comments

Comments
 (0)