Skip to content

apinames: Fix out-of-scope reference of a static array.

* apinames.c (names_dump): For WATCOM_LBC format, the
  DLL name with no suffix is constructed on a static
  array temp[], but the scope is closed before use it.
  The declaration of temp[] is moved to the wider
  scope for the dumping part to refer it.

During the test on Solaris 11, I found that apinames output for Watcom linker has a garbage after the library name, like,

++_FTC_CMapCache_Lookup.FREETYPE<A4><81>.FTC_CMapCache_Lookup
++_FTC_CMapCache_New.FREETYPE<A4><81>.FTC_CMapCache_New
++_FTC_ImageCache_Lookup.FREETYPE<A4><81>.FTC_ImageCache_Lookup
++_FTC_ImageCache_LookupScaler.FREETYPE<A4><81>.FTC_ImageCache_LookupScaler
++_FTC_ImageCache_New.FREETYPE<A4><81>.FTC_ImageCache_New
++_FTC_Manager_Done.FREETYPE<A4><81>.FTC_Manager_Done
...

It seems that the static declaration of temp[] array for the library basename (with no suffix) is in too narrow scope. It should be moved to wider scope, to be used by the dumping part.

apinames.c:194-213

    194       /* we must omit the `.dll' suffix from the library name */
    195       dot = strchr( dll_name, '.' );
    196       if ( dot )
    197       {
    198         char  temp[512];
    199         int   len = dot - dll_name;
    200
    201
    202         if ( len > (int)( sizeof ( temp ) - 1 ) )
    203           len = sizeof ( temp ) - 1;
    204
    205         memcpy( temp, dll_name, len );
    206         temp[len] = 0;
    207
    208         dll_name = (const char*)temp;
    209       }
    210
    211       for ( nn = 0; nn < num_names; nn++ )
    212         fprintf( out, "++_%s.%s.%s\n",
    213                       the_names[nn].name, dll_name, the_names[nn].name );

Merge request reports

Loading