This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR fortran/24005


Steve Kargl wrote:
> The problem, again discussed in the PR, is that gfortran was
> passing a NULL pointer to strcmp.
> 
> OK for mainline?

This is not yet ok ...

> --- 926,933 ----
>   	if (p->sym == q->sym)
>   	  continue;		/* Duplicates OK here */
>   
> ! 	if (p->sym->name && q->sym->name && p->sym->module && q->sym->module
> ! 	    && strcmp (p->sym->name, q->sym->name) == 0
>   	    && strcmp (p->sym->module, q->sym->module) == 0)
>   	  continue;

p->sym->name and q->sym->name should never be NULL.  Furthermore, the module
name needn't be set, as interfaces can reference symbols in the current scope,
IOW the correct check would be:

if (strcmp (p->sym->name, q->sym->name) == 0
    && ((!p->sym->module && !q->sym->module)
        || (p->sym->module && q->sym->module
            && strcmp (p->sym->module, q->sym->module) == 0)))

NB I remember that we stumbled across a very similar bug when I introduced the
string table changes, which it turned out I had missed, because glibc's strcmp
does "the right thing" with NULL arguments unlike FreeBSD's.  Alternatively,
(if I understand C well enough) we could simply compare the string pointers
(they're allocated by gfc_get_string) like so:

if (p->sym->name == q->sym->name && p->sym->module == q->sym->module)

- Tobi


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]