Skip to content

Commit 3c08fde

Browse files
committed
fix: make setAmxString safe for sizeof() buffers
1 parent 2e80703 commit 3c08fde

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

reapi/src/amxxmodule.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,13 @@ char* getAmxString(cell* src, char* dest, size_t max, size_t* len)
238238

239239
void setAmxString(cell* dest, const char* string, size_t max)
240240
{
241-
while (*string && max--)
241+
if (!dest || max == 0)
242+
return;
243+
244+
// reserve 1 cell for term null
245+
size_t limit = max - 1;
246+
247+
while (*string && limit--)
242248
*dest++ = (cell)*string++;
243249

244250
*dest = 0;

0 commit comments

Comments
 (0)