From 0d958cbc69e2c8e420a769affd697dee7bcdd775 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Thu, 13 Feb 2025 20:46:11 -0600 Subject: [PATCH] Update: Switch from memcpy() to memmove() just in case. This is a library and cannot guarantee that the sources do not overlap. Change to `memmove()` to play it safe. --- level_0/f_color/c/color.c | 50 +++++++++++++++++++-------------------- level_0/f_color/c/color.h | 12 +++++----- level_0/f_color/c/private-color.c | 16 ++++++------- level_0/f_color/c/private-color.h | 4 ++-- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/level_0/f_color/c/color.c b/level_0/f_color/c/color.c index 5a1a0e2..b3e2cdc 100644 --- a/level_0/f_color/c/color.c +++ b/level_0/f_color/c/color.c @@ -245,29 +245,29 @@ extern "C" { } if (color1.used) { - memcpy(buffer->string + buffer->used, color1.string, sizeof(f_char_t) * color1.used); + memmove(buffer->string + buffer->used, color1.string, sizeof(f_char_t) * color1.used); buffer->used += color1.used; if (color2.used) { if (format.medium.used) { - memcpy(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); + memmove(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); buffer->used += format.medium.used; } - memcpy(buffer->string + buffer->used, color2.string, sizeof(f_char_t) * color2.used); + memmove(buffer->string + buffer->used, color2.string, sizeof(f_char_t) * color2.used); buffer->used += color2.used; if (color3.used) { if (format.medium.used) { - memcpy(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); + memmove(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); buffer->used += format.medium.used; } - memcpy(buffer->string + buffer->used, color3.string, sizeof(f_char_t) * color3.used); + memmove(buffer->string + buffer->used, color3.string, sizeof(f_char_t) * color3.used); buffer->used += color3.used; } @@ -275,7 +275,7 @@ extern "C" { } if (format.end.used) { - memcpy(buffer->string + buffer->used, format.end.string, sizeof(f_char_t) * format.end.used); + memmove(buffer->string + buffer->used, format.end.string, sizeof(f_char_t) * format.end.used); buffer->used += format.end.used; } @@ -298,40 +298,40 @@ extern "C" { } if (color1.used) { - memcpy(buffer->string + buffer->used, color1.string, sizeof(f_char_t) * color1.used); + memmove(buffer->string + buffer->used, color1.string, sizeof(f_char_t) * color1.used); buffer->used += color1.used; if (color2.used) { if (format.medium.used) { - memcpy(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); + memmove(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); buffer->used += format.medium.used; } - memcpy(buffer->string + buffer->used, color2.string, sizeof(f_char_t) * color2.used); + memmove(buffer->string + buffer->used, color2.string, sizeof(f_char_t) * color2.used); buffer->used += color2.used; if (color3.used) { if (format.medium.used) { - memcpy(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); + memmove(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); buffer->used += format.medium.used; } - memcpy(buffer->string + buffer->used, color3.string, sizeof(f_char_t) * color3.used); + memmove(buffer->string + buffer->used, color3.string, sizeof(f_char_t) * color3.used); buffer->used += color3.used; if (color4.used) { if (format.medium.used) { - memcpy(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); + memmove(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); buffer->used += format.medium.used; } - memcpy(buffer->string + buffer->used, color4.string, sizeof(f_char_t) * color4.used); + memmove(buffer->string + buffer->used, color4.string, sizeof(f_char_t) * color4.used); buffer->used += color4.used; } @@ -340,7 +340,7 @@ extern "C" { } if (format.end.used) { - memcpy(buffer->string + buffer->used, format.end.string, sizeof(f_char_t) * format.end.used); + memmove(buffer->string + buffer->used, format.end.string, sizeof(f_char_t) * format.end.used); buffer->used += format.end.used; } @@ -363,57 +363,57 @@ extern "C" { } if (format.begin.used) { - memcpy(buffer->string + buffer->used, format.begin.string, sizeof(f_char_t) * format.begin.used); + memmove(buffer->string + buffer->used, format.begin.string, sizeof(f_char_t) * format.begin.used); buffer->used += format.begin.used; } if (color1.used) { - memcpy(buffer->string + buffer->used, color1.string, sizeof(f_char_t) * color1.used); + memmove(buffer->string + buffer->used, color1.string, sizeof(f_char_t) * color1.used); buffer->used += color1.used; if (color2.used) { if (format.medium.used) { - memcpy(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); + memmove(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); buffer->used += format.medium.used; } - memcpy(buffer->string + buffer->used, color2.string, sizeof(f_char_t) * color2.used); + memmove(buffer->string + buffer->used, color2.string, sizeof(f_char_t) * color2.used); buffer->used += color2.used; if (color3.used) { if (format.medium.used) { - memcpy(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); + memmove(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); buffer->used += format.medium.used; } - memcpy(buffer->string + buffer->used, color3.string, sizeof(f_char_t) * color3.used); + memmove(buffer->string + buffer->used, color3.string, sizeof(f_char_t) * color3.used); buffer->used += color3.used; if (color4.used) { if (format.medium.used) { - memcpy(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); + memmove(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); buffer->used += format.medium.used; } - memcpy(buffer->string + buffer->used, color4.string, sizeof(f_char_t) * color4.used); + memmove(buffer->string + buffer->used, color4.string, sizeof(f_char_t) * color4.used); buffer->used += color4.used; if (color5.used) { if (format.medium.used) { - memcpy(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); + memmove(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); buffer->used += format.medium.used; } - memcpy(buffer->string + buffer->used, color5.string, sizeof(f_char_t) * color5.used); + memmove(buffer->string + buffer->used, color5.string, sizeof(f_char_t) * color5.used); buffer->used += color5.used; } @@ -423,7 +423,7 @@ extern "C" { } if (format.end.used) { - memcpy(buffer->string + buffer->used, format.end.string, sizeof(f_char_t) * format.end.used); + memmove(buffer->string + buffer->used, format.end.string, sizeof(f_char_t) * format.end.used); buffer->used += format.end.used; } diff --git a/level_0/f_color/c/color.h b/level_0/f_color/c/color.h index 0ed0620..02cd32e 100644 --- a/level_0/f_color/c/color.h +++ b/level_0/f_color/c/color.h @@ -59,7 +59,7 @@ extern "C" { * * Errors (with error bit) from: f_memory_array_increase_by() * - * @see memcpy() + * @see memmove() * * @see f_memory_array_increase_by() */ @@ -89,7 +89,7 @@ extern "C" { * * Errors (with error bit) from: f_memory_array_increase_by() * - * @see memcpy() + * @see memmove() * * @see f_memory_array_increase_by() */ @@ -122,7 +122,7 @@ extern "C" { * * Errors (with error bit) from: f_memory_array_increase_by() * - * @see memcpy() + * @see memmove() * * @see f_memory_array_increase_by() */ @@ -158,7 +158,7 @@ extern "C" { * * Errors (with error bit) from: f_memory_array_increase_by() * - * @see memcpy() + * @see memmove() * * @see f_memory_array_increase_by() */ @@ -197,7 +197,7 @@ extern "C" { * * Errors (with error bit) from: f_memory_array_increase_by() * - * @see memcpy() + * @see memmove() * * @see f_memory_array_increase_by() */ @@ -241,7 +241,7 @@ extern "C" { * * Errors (with error bit) from: f_memory_array_increase_by() * - * @see memcpy() + * @see memmove() * * @see f_memory_array_increase_by() */ diff --git a/level_0/f_color/c/private-color.c b/level_0/f_color/c/private-color.c index 6e8c013..bb4f256 100644 --- a/level_0/f_color/c/private-color.c +++ b/level_0/f_color/c/private-color.c @@ -14,19 +14,19 @@ extern "C" { } if (format.begin.used) { - memcpy(buffer->string + buffer->used, format.begin.string, sizeof(f_char_t) * format.begin.used); + memmove(buffer->string + buffer->used, format.begin.string, sizeof(f_char_t) * format.begin.used); buffer->used += format.begin.used; } if (color1.used) { - memcpy(buffer->string + buffer->used, color1.string, sizeof(f_char_t) * color1.used); + memmove(buffer->string + buffer->used, color1.string, sizeof(f_char_t) * color1.used); buffer->used += color1.used; } if (format.end.used) { - memcpy(buffer->string + buffer->used, format.end.string, sizeof(f_char_t) * format.end.used); + memmove(buffer->string + buffer->used, format.end.string, sizeof(f_char_t) * format.end.used); buffer->used += format.end.used; } @@ -46,31 +46,31 @@ extern "C" { } if (format.begin.used) { - memcpy(buffer->string + buffer->used, format.begin.string, sizeof(f_char_t) * format.begin.used); + memmove(buffer->string + buffer->used, format.begin.string, sizeof(f_char_t) * format.begin.used); buffer->used += format.begin.used; } if (color1.used) { - memcpy(buffer->string + buffer->used, color1.string, sizeof(f_char_t) * color1.used); + memmove(buffer->string + buffer->used, color1.string, sizeof(f_char_t) * color1.used); buffer->used += color1.used; if (color2.used) { if (format.medium.used) { - memcpy(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); + memmove(buffer->string + buffer->used, format.medium.string, sizeof(f_char_t) * format.medium.used); buffer->used += format.medium.used; } - memcpy(buffer->string + buffer->used, color2.string, sizeof(f_char_t) * color2.used); + memmove(buffer->string + buffer->used, color2.string, sizeof(f_char_t) * color2.used); buffer->used += color2.used; } } if (format.end.used) { - memcpy(buffer->string + buffer->used, format.end.string, sizeof(f_char_t) * format.end.used); + memmove(buffer->string + buffer->used, format.end.string, sizeof(f_char_t) * format.end.used); buffer->used += format.end.used; } diff --git a/level_0/f_color/c/private-color.h b/level_0/f_color/c/private-color.h index 79fe241..27944fe 100644 --- a/level_0/f_color/c/private-color.h +++ b/level_0/f_color/c/private-color.h @@ -33,7 +33,7 @@ extern "C" { * * Errors (with error bit) from: f_memory_array_increase_by() * - * @see memcpy() + * @see memmove() * * @see f_memory_array_increase_by() * @@ -62,7 +62,7 @@ extern "C" { * * Errors (with error bit) from: f_memory_array_increase_by() * - * @see memcpy() + * @see memmove() * * @see f_memory_array_increase_by() * -- 1.8.3.1