mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-05-06 21:08:04 +02:00
util: replace a strncpy with a memcpy
We know exactly the lengths of everything involved here so let's use memcpy. This way we don't need the stringop-truncation warning (a pragma clang doesn't support anyway).
This commit is contained in:
parent
3e2e43e352
commit
865d7152e0
1 changed files with 3 additions and 7 deletions
|
|
@ -184,9 +184,6 @@ strreplace(const char *string, const char *separator, const char *replacement)
|
|||
char *r = calloc(max + 1, 1); /* the result, one extra for terminating \0 */
|
||||
char *destptr = r;
|
||||
|
||||
/* our strncpy calls truncate the second argument, we know... */
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-truncation"
|
||||
while (next) {
|
||||
size_t len = next - current;
|
||||
/* silently truncate because we really don't care about this
|
||||
|
|
@ -195,11 +192,11 @@ strreplace(const char *string, const char *separator, const char *replacement)
|
|||
break;
|
||||
|
||||
/* Copy the source string over, then append the separator */
|
||||
strncpy(destptr, current, len);
|
||||
memcpy(destptr, current, len);
|
||||
destptr += len;
|
||||
if (destptr + rlen > r + max)
|
||||
break;
|
||||
strncpy(destptr, replacement, rlen);
|
||||
memcpy(destptr, replacement, rlen);
|
||||
destptr += rlen;
|
||||
|
||||
current = next + splen;
|
||||
|
|
@ -213,10 +210,9 @@ strreplace(const char *string, const char *separator, const char *replacement)
|
|||
/* silently truncate because we really don't care about this
|
||||
* case */
|
||||
if (destptr + len <= r + max) {
|
||||
strncpy(destptr, current, len);
|
||||
memcpy(destptr, current, len);
|
||||
destptr += len;
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
void *tmp = realloc(r, (destptr - r) + 1);
|
||||
assert(tmp);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue