mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-27 16:06:16 +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,
|
||||
const char *to_copy)
|
||||
{
|
||||
gsize copy_count = strlen (to_copy);
|
||||
if (copy_count <= *buffer_size)
|
||||
memset (buffer, 0x20, copy_count);
|
||||
else
|
||||
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;
|
||||
gsize copy_count = MIN (strlen (to_copy), *buffer_size - 1);
|
||||
memset (buffer, 0x20, copy_count);
|
||||
strncpy_s (buffer, *buffer_size, to_copy, _TRUNCATE);
|
||||
*buffer_size -= copy_count;
|
||||
return &buffer[copy_count];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user