On 15/10/2020 15:06, Frank Kühndel wrote:

On 10/15/20 2:09 PM, Sebastian Huber wrote:
From: Frank Kühndel<frank.kuehn...@embedded-brains.de>

The compiler warning was:

../../../cpukit/libmisc/rtems-fdt/rtems-fdt.c:267:5: warning:
'strncpy' specified bound depends on the length of the source argument
    267 |     strncpy(path, name, namelen);
        |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

It turns out that the `strncpy()` nor the buffer `path` is needed when
one uses `strncmp()` instead of `strcmp()`. This needs some change to
the algorithm but has the advantage that `name` is never truncated
to the size of the buffer `path`.
Does it help to use bsearch() to simplify this code further?
Nice! I did not even know (or remember about) bsearch().

No, it wont help. bsearch() works on "similar" objects (e.g. two
strings). The function I modified searches a string in an array of
'rtems_fdt_index_entry' objects. To make that work, one must create a
dummy 'rtems_fdt_index_entry' containing that string.

Moreover, there remains the problem that the 'name' string has an
artificially restricted length which must be convoyed to the 'compar()'
function used by 'bseach()'.

Finally, rtems-fdt.c is - most likely - dead code. So, I would end up
spending my time on brushing up dead code.

Ok, thanks for having a look at this. I checked in the patch as is.

This was the last warning in the architecture-independent part (except the old network stack).

_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Reply via email to