diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-05-06 07:49:52 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-05-06 07:49:52 -0600 |
commit | 4d923d81c73229b834f9b2ee45185e1c07ef0841 (patch) | |
tree | 37a6eb48fec4f1d2bd40880021edda746c9f8e07 | |
parent | fdf3afe510e05c44e81ab7d0bacf41cd982415df (diff) | |
download | nuttx-4d923d81c73229b834f9b2ee45185e1c07ef0841.tar.gz nuttx-4d923d81c73229b834f9b2ee45185e1c07ef0841.tar.bz2 nuttx-4d923d81c73229b834f9b2ee45185e1c07ef0841.zip |
BINFMT: Fix an error in the symbol search function. Noted by Pelle Windestam
-rw-r--r-- | nuttx/ChangeLog | 2 | ||||
-rw-r--r-- | nuttx/binfmt/symtab_findorderedbyname.c | 19 |
2 files changed, 13 insertions, 8 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 806f1cfc0..565fe2d9a 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -7292,3 +7292,5 @@ integration of new timer features. From Bob Doiron (2014-5-5). * drivers/timer.c and include/nuttx/timer.h: Timer driver updates from Bob Doiron (2014-5-5). + * binfmt/symtab_findorderedbyname.c: Fix an error in the symbol search + function. Noted by Pelle Windestam (2014-5-6). diff --git a/nuttx/binfmt/symtab_findorderedbyname.c b/nuttx/binfmt/symtab_findorderedbyname.c index a678788e7..7ca2ea033 100644 --- a/nuttx/binfmt/symtab_findorderedbyname.c +++ b/nuttx/binfmt/symtab_findorderedbyname.c @@ -1,7 +1,7 @@ /**************************************************************************** * binfmt/symtab_findorderedbyname.c * - * Copyright (C) 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -73,10 +73,9 @@ * Find the symbol in the symbol table with the matching name. * This version assumes that table ordered with respect to symbol name. * - * This function uses qsort() to implement the search and, hence, is a lot - * larger than symbtab_findbyname(). This function not be used, unless - * the symbol table is large and the performance benefit is worth the - * increased size. + * This function is a lot larger than symbtab_findbyname(). This function + * not be used, unless the symbol table is large and the performance + * benefit is worth the increased size. * * Returned Value: * A reference to the symbol table entry if an entry with the matching @@ -89,7 +88,7 @@ symtab_findorderedbyname(FAR const struct symtab_s *symtab, FAR const char *name, int nsyms) { int low = 0; - int high = nsyms -1; + int high = nsyms - 1; int mid; int cmp; @@ -108,9 +107,13 @@ symtab_findorderedbyname(FAR const struct symtab_s *symtab, cmp = strcmp(name, symtab[mid].sym_name); if (cmp < 0) { - /* name < symtab[mid].sym_name */ + /* name < symtab[mid].sym_name + * + * NOTE: Because of truncation in the calculation of 'mid'. + * 'mid' could be equal to 'low' + */ - high = mid - 1; + high = mid > low ? mid - 1 : low; } else if (cmp > 0) { |