[rtems commit] Revert "rtems-fdt / shell - Fix string truncation warning"
Sebastian Huber
sebh at rtems.org
Fri Oct 16 04:23:13 UTC 2020
Module: rtems
Branch: master
Commit: e2250eeb94ee077a3b8227f9e63d78b4f4435bbc
Changeset: http://git.rtems.org/rtems/commit/?id=e2250eeb94ee077a3b8227f9e63d78b4f4435bbc
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Fri Oct 16 06:22:45 2020 +0200
Revert "rtems-fdt / shell - Fix string truncation warning"
This reverts commit 355bc37ad35a7d67a7209130171febe805c67f62.
---
cpukit/libmisc/rtems-fdt/rtems-fdt.c | 40 +++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/cpukit/libmisc/rtems-fdt/rtems-fdt.c b/cpukit/libmisc/rtems-fdt/rtems-fdt.c
index 0ea3653..39e70bf 100644
--- a/cpukit/libmisc/rtems-fdt/rtems-fdt.c
+++ b/cpukit/libmisc/rtems-fdt/rtems-fdt.c
@@ -248,46 +248,48 @@ rtems_fdt_index_find_by_name(rtems_fdt_index* index,
{
int min = 0;
int max = index->num_entries;
+ char path[256];
+ const char* cmp_name = name;
+
/*
* Handle trailing slash case.
*/
- size_t namelen = strlen(name);
+ int namelen = strlen(name);
if (namelen > 0 && name[namelen-1] == '/')
{
namelen--;
+
+ if (namelen >= (int)sizeof(path) - 1)
+ {
+ namelen = sizeof(path) - 1;
+ }
+
+ strncpy(path, name, namelen);
+ path[namelen] = 0;
+ cmp_name = path;
}
/* Binary search for the name. */
while (min < max)
{
int middle = (min + max) / 2;
- int cmp = strncmp(name, index->entries[middle].name, namelen);
- if (cmp == 0)
- {
- /* 'namelen' characters are equal but 'index->entries[middle].name' */
- /* could have additional characters. */
- if (index->entries[middle].name[namelen] == '\0')
- {
- /* Found it. */
- return index->entries[middle].offset;
- }
- else
- {
- /* 'index->entries[middle].name' is longer than 'name'. */
- cmp = -1;
- }
- }
+ int cmp = strcmp(cmp_name, index->entries[middle].name);
if (cmp < 0)
{
/* Look lower than here. */
max = middle;
}
- else
+ else if (cmp > 0)
{
/* Look higher than here. */
min = middle + 1;
}
- }
+ else
+ {
+ /* Found it. */
+ return index->entries[middle].offset;
+ }
+ }
/* Didn't find it. */
return -FDT_ERR_NOTFOUND;
More information about the vc
mailing list