mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-28 08:26:14 +01:00
Fix the math in copy_chars
Now we end up returning a pointer to the end of the buffer after we run out of space. On subsequent calls copy_count will end up being 0.
This commit is contained in:
parent
fbd7a37e1a
commit
0908e6a8e7
@ -1054,16 +1054,10 @@ copy_chars (char *buffer,
|
|||||||
gsize *buffer_size,
|
gsize *buffer_size,
|
||||||
const char *to_copy)
|
const char *to_copy)
|
||||||
{
|
{
|
||||||
gsize copy_count = strlen (to_copy);
|
gsize copy_count = MIN (strlen (to_copy), *buffer_size - 1);
|
||||||
if (copy_count <= *buffer_size)
|
memset (buffer, 0x20, copy_count);
|
||||||
memset (buffer, 0x20, copy_count);
|
strncpy_s (buffer, *buffer_size, to_copy, _TRUNCATE);
|
||||||
else
|
*buffer_size -= copy_count;
|
||||||
memset (buffer, 0x20, *buffer_size);
|
|
||||||
strncpy_s (buffer, *buffer_size, to_copy, copy_count);
|
|
||||||
if (*buffer_size >= copy_count)
|
|
||||||
*buffer_size -= copy_count;
|
|
||||||
else
|
|
||||||
*buffer_size = 0;
|
|
||||||
return &buffer[copy_count];
|
return &buffer[copy_count];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user