Skip to content

Commit 81a0e22

Browse files
committed
Add documentation for out-of-bounds situations.
1 parent 0d249bf commit 81a0e22

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

plugins/include/string.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ native int StringToIntEx(const char[] str, int &result, int nBase=10);
204204
/**
205205
* Converts a string to a 64-bit integer.
206206
*
207+
* @note If the value is outside the range of representable values,
208+
* If the value is positive, this function will return INT64_MAX.
209+
* If the value is negative, this function will return INT64_MIN.
210+
*
207211
* @param str String to convert.
208212
* @param result Array to store the upper and lower
209213
* 32-bits of the 64-bit integer.
@@ -215,6 +219,10 @@ native int StringToInt64(const char[] str, int result[2], int nBase=10);
215219
/**
216220
* Converts a string to an int64 type value.
217221
*
222+
* @note If the value is outside the range of representable values,
223+
* If the value is positive, this function will return INT64_MAX.
224+
* If the value is negative, this function will return INT64_MIN.
225+
*
218226
* @param str String to convert.
219227
* @param nBase Numerical base to use. 10 is default.
220228
* @param nConsumed Number of characters consumed.

plugins/testsuite/mock/test_string.sp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,40 @@ void Test_StringToI64()
105105
StringToI64("1_234_567", .nConsumed=nConsumed),
106106
1);
107107
AssertEq("nConsumed 1_234_567", nConsumed, 1);
108+
109+
AssertInt64Eq(
110+
"result 9223372036854775807",
111+
StringToI64("9223372036854775807", .nConsumed=nConsumed),
112+
9223372036854775807);
113+
AssertEq("nConsumed 9223372036854775807", nConsumed, 19);
114+
115+
AssertInt64Eq(
116+
"result 9223372036854775808",
117+
StringToI64("9223372036854775807", .nConsumed=nConsumed),
118+
9223372036854775807);
119+
AssertEq("nConsumed 9223372036854775808", nConsumed, 19);
120+
121+
AssertInt64Eq(
122+
"result 92233720368547758070",
123+
StringToI64("9223372036854775807", .nConsumed=nConsumed),
124+
9223372036854775807);
125+
AssertEq("nConsumed 92233720368547758070", nConsumed, 19);
126+
127+
AssertInt64Eq(
128+
"result -9223372036854775808",
129+
StringToI64("-9223372036854775808", .nConsumed=nConsumed),
130+
-9223372036854775807-1);
131+
AssertEq("nConsumed -9223372036854775808", nConsumed, 20);
132+
133+
AssertInt64Eq(
134+
"result -9223372036854775809",
135+
StringToI64("-9223372036854775808", .nConsumed=nConsumed),
136+
-9223372036854775807-1);
137+
AssertEq("nConsumed -9223372036854775809", nConsumed, 20);
138+
139+
AssertInt64Eq(
140+
"result -92233720368547758080",
141+
StringToI64("-9223372036854775808", .nConsumed=nConsumed),
142+
-9223372036854775807-1);
143+
AssertEq("nConsumed -92233720368547758080", nConsumed, 20);
108144
}

0 commit comments

Comments
 (0)