BINFMT: Fix an error in the symbol search function. Noted by Pelle Windestam

This commit is contained in:
Gregory Nutt
2014-05-06 07:49:52 -06:00
parent 88abca5e5e
commit 227cd6ca66
2 changed files with 13 additions and 8 deletions
+2
View File
@@ -7292,3 +7292,5 @@
integration of new timer features. From Bob Doiron (2014-5-5). integration of new timer features. From Bob Doiron (2014-5-5).
* drivers/timer.c and include/nuttx/timer.h: Timer driver updates from * drivers/timer.c and include/nuttx/timer.h: Timer driver updates from
Bob Doiron (2014-5-5). Bob Doiron (2014-5-5).
* binfmt/symtab_findorderedbyname.c: Fix an error in the symbol search
function. Noted by Pelle Windestam (2014-5-6).
+11 -8
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* binfmt/symtab_findorderedbyname.c * 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> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * 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. * Find the symbol in the symbol table with the matching name.
* This version assumes that table ordered with respect to symbol 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 * This function is a lot larger than symbtab_findbyname(). This function
* larger than symbtab_findbyname(). This function not be used, unless * not be used, unless the symbol table is large and the performance
* the symbol table is large and the performance benefit is worth the * benefit is worth the increased size.
* increased size.
* *
* Returned Value: * Returned Value:
* A reference to the symbol table entry if an entry with the matching * 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) FAR const char *name, int nsyms)
{ {
int low = 0; int low = 0;
int high = nsyms -1; int high = nsyms - 1;
int mid; int mid;
int cmp; int cmp;
@@ -108,9 +107,13 @@ symtab_findorderedbyname(FAR const struct symtab_s *symtab,
cmp = strcmp(name, symtab[mid].sym_name); cmp = strcmp(name, symtab[mid].sym_name);
if (cmp < 0) 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) else if (cmp > 0)
{ {