diff options
author | LRN <lrn1986@gmail.com> | 2021-05-15 04:21:37 +0000 |
---|---|---|
committer | Руслан Ижбулатов <lrn1986@gmail.com> | 2021-06-08 08:38:59 +0000 |
commit | 0908e6a8e7370be6ebb8caf79d8bfe9920cd8c11 (patch) | |
tree | a2e32417452633009901283f365c37ccc12faa92 | |
parent | fbd7a37e1a126bdfe638048bf5dcbd718e645fd7 (diff) | |
download | glib-0908e6a8e7370be6ebb8caf79d8bfe9920cd8c11.tar.gz |
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.
-rw-r--r-- | glib/gwin32.c | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/glib/gwin32.c b/glib/gwin32.c index c710ec603..f4590916f 100644 --- a/glib/gwin32.c +++ b/glib/gwin32.c @@ -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]; } |