Commit 80bd73c
Daniel Thompson
kdb: Replace double memcpy() with memmove() in kdb_read()
At several points in kdb_read() there are variants of the following
code pattern (with offsets slightly altered):
memcpy(tmpbuffer, cp, lastchar - cp);
memcpy(cp-1, tmpbuffer, lastchar - cp);
*(--lastchar) = '\0';
There is no need to use tmpbuffer here, since we can use memmove() instead
so refactor in the obvious way. Additionally the strings that are being
copied are already properly terminated so let's also change the code so
that the library calls also move the terminator.
Changing how the terminators are managed has no functional effect for now
but might allow us to retire lastchar at a later point. lastchar, although
stored as a pointer, is functionally equivalent to caching strlen(buffer).
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20240424-kgdb_read_refactor-v3-6-f236dbe9828d@linaro.org
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>1 parent c9b51dd commit 80bd73c
1 file changed
Lines changed: 7 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
278 | 275 | | |
279 | 276 | | |
280 | 277 | | |
| |||
291 | 288 | | |
292 | 289 | | |
293 | 290 | | |
294 | | - | |
295 | | - | |
296 | | - | |
| 291 | + | |
| 292 | + | |
297 | 293 | | |
298 | 294 | | |
299 | 295 | | |
| |||
398 | 394 | | |
399 | 395 | | |
400 | 396 | | |
401 | | - | |
402 | | - | |
403 | | - | |
| 397 | + | |
| 398 | + | |
404 | 399 | | |
405 | 400 | | |
406 | 401 | | |
| |||
0 commit comments