diff options
Diffstat (limited to 'gdb/utils.c')
-rw-r--r-- | gdb/utils.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/gdb/utils.c b/gdb/utils.c index eadd1681611..d0f2eddfa69 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -2368,7 +2368,29 @@ strcmp_iw (const char *string1, const char *string2) If a list is sorted according to this function and if you want to find names in the list that match some fixed NAME according to strcmp_iw(LIST_ELT, NAME), then the place to start looking is right - where this function would put NAME. */ + where this function would put NAME. + + Here are some examples of why using strcmp to sort is a bad idea: + + Whitespace example: + + Say your partial symtab contains: "foo<char *>", "goo". Then, if + we try to do a search for "foo<char*>", strcmp will locate this + after "foo<char *>" and before "goo". Then lookup_partial_symbol + will start looking at strings beginning with "goo", and will never + see the correct match of "foo<char *>". + + Parenthesis example: + + In practice, this is less like to be an issue, but I'll give it a + shot. Let's assume that '$' is a legitimate character to occur in + symbols. (Which may well even be the case on some systems.) Then + say that the partial symbol table contains "foo$" and "foo(int)". + strcmp will put them in this order, since '$' < '('. Now, if the + user searches for "foo", then strcmp will sort "foo" before "foo$". + Then lookup_partial_symbol will notice that strcmp_iw("foo$", + "foo") is false, so it won't proceed to the actual match of + "foo(int)" with "foo". */ int strcmp_iw_ordered (const char *string1, const char *string2) @@ -2743,8 +2765,8 @@ gdb_realpath (const char *filename) if (rp == NULL) rp = filename; return xstrdup (rp); - } # endif + } #endif /* HAVE_REALPATH */ /* Method 2: The host system (i.e., GNU) has the function |