Changeset 3730


Ignore:
Timestamp:
Mar 18, 2011, 12:54:25 AM (14 years ago)
Author:
bird
Message:

0.6: Backported r3729: emxomf.c: applied emxomf-03-fix-symbol-too-long.diff with modifications and a fix (import lib). Fixes #220.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/libc-0.6/src/emx/src/emxomf/emxomf.c

    r2983 r3730  
    795795}
    796796
    797 
    798 
    799 
    800 
    801 /* Put the string pszName into the current OMF record.
    802    In the OMF record, the string is preceded by a length byte.  The
    803    string length must not exceed 255; if it is too long, display a
    804    warning and truncate the string.  Moreover, there must be enough
    805    space left in the OMF record; if there isn't, display an error
    806    message and abort. */
    807 
    808 static void put_nstr(const char *pszName, size_t cch)
     797/* Put the string pszName into the given buffer pOutBuf (which must be at least
     798   256 bytes long). The string length must not exceed 255 bytes (OMF format
     799   requirement); if it is too long, display a warning and truncate the string.
     800   The string returned in pOutBuf is zero-terminated. The function returns the
     801   length of the resulting string. */
     802
     803static int make_nstr (const char *pszName, size_t cch, char *pszOutBuf)
    809804{
    810805    if (    cch > SYMBOL_MAX_LENGTH
     
    824819        assert(psz - &szHash[0] == SYMBOL_HASH_LENGTH);
    825820
    826         if (!fits(1 + SYMBOL_MAX_LENGTH + SYMBOL_HASH_LENGTH))
    827             doesn_fit();
    828         out_data[out_idx++] = SYMBOL_MAX_LENGTH + SYMBOL_HASH_LENGTH;
    829         memcpy(out_data + out_idx, pszName, SYMBOL_MAX_LENGTH);
    830         out_idx += SYMBOL_MAX_LENGTH;
    831         memcpy(out_data + out_idx, szHash, SYMBOL_HASH_LENGTH);
    832         out_idx += SYMBOL_HASH_LENGTH;
     821        memcpy(pszOutBuf, pszName, SYMBOL_MAX_LENGTH);
     822        memcpy(pszOutBuf + SYMBOL_MAX_LENGTH, szHash, SYMBOL_HASH_LENGTH);
     823        pszOutBuf[SYMBOL_MAX_LENGTH + SYMBOL_HASH_LENGTH] = '\0';
    833824
    834825        warning ("Truncated symbol '%.*s' to '%.*s%s'", cch, pszName, SYMBOL_MAX_LENGTH, pszName, szHash);
     826
     827        cch = SYMBOL_MAX_LENGTH + SYMBOL_HASH_LENGTH;
    835828    }
    836829    else
     
    838831        assert(cch <= 0xff);
    839832        cch &= 0xff;
    840         if (!fits(1+cch))
    841             doesn_fit();
    842         out_data[out_idx++] = (byte)cch;
    843         memcpy(out_data+out_idx, pszName, cch);
    844         out_idx += cch;
    845     }
     833        memcpy(pszOutBuf, pszName, cch);
     834        pszOutBuf[cch] = '\0';
     835    }
     836    return cch;
     837}
     838
     839/* Put the string pszName into the current OMF record.
     840   In the OMF record, the string is preceded by a length byte.  The
     841   string length must not exceed 255; if it is too long, display a
     842   warning and truncate the string.  Moreover, there must be enough
     843   space left in the OMF record; if there isn't, display an error
     844   message and abort. */
     845
     846static void put_nstr(const char *pszName, size_t cch)
     847{
     848    char szName[256];
     849
     850    cch = make_nstr(pszName, cch, szName);
     851   
     852    if (!fits(1 + cch))
     853        doesn_fit();
     854    out_data[out_idx++] = (byte)cch;
     855    memcpy(out_data+out_idx, szName, cch);
     856    out_idx += cch;
    846857}
    847858
     
    12001211  int i;
    12011212  const char *pub_name;
     1213  char szPubName[256];
     1214  int cchPubName;
    12021215
    12031216  for (i = 0; i < sym_count - 1; ++i)
    12041217    if (sym_ptr[i].n_type == (N_INDR|N_EXT) && sym_ptr[i+1].n_type == N_EXT)
    12051218      {
     1219        pub_name = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
     1220        if (strip_underscore (pub_name))
     1221          ++pub_name;
     1222        cchPubName = make_nstr (pub_name, strlen(pub_name), szPubName);
     1223
    12061224        init_rec (ALIAS);
    1207         put_sym ((const char *)(str_ptr + sym_ptr[i].n_un.n_strx));
     1225        put_8 (cchPubName);
     1226        put_mem (szPubName, cchPubName);
    12081227        put_sym ((const char *)(str_ptr + sym_ptr[i+1].n_un.n_strx));
    12091228        write_rec ();
     
    12111230        if (out_lib != NULL)
    12121231          {
    1213             pub_name = (const char *)(str_ptr + sym_ptr[i].n_un.n_strx);
    1214             if (strip_underscore (pub_name))
    1215               ++pub_name;
    1216             if (omflib_add_pub (out_lib, pub_name, mod_page, lib_errmsg) != 0)
     1232            if (omflib_add_pub (out_lib, szPubName, mod_page, lib_errmsg) != 0)
    12171233              error (lib_errmsg);
    12181234          }
     
    12481264  dword address;
    12491265  char  szName[256];
     1266  char  szPubName[256];
     1267  int   cchPubName;
    12501268
    12511269  started = FALSE;
     
    12661284                if ( sym_ptr[i].n_type >= N_WEAKU && sym_ptr[i].n_type <= N_WEAKB )
    12671285                    name = weak_process_name(&sym_ptr[i], name, szName, sizeof(szName));
     1286                pub_name = name;
     1287                if (strip_underscore (pub_name))
     1288                  ++pub_name;
     1289                cchPubName = make_nstr (pub_name, strlen (pub_name), szPubName);
    12681290
    12691291                if (    out_lib != NULL
     
    12741296                         ||  sym_ptr[i].n_type == N_WEAKD ) )
    12751297                  {
    1276                     pub_name = name;
    1277                     if (strip_underscore (pub_name))
    1278                       ++pub_name;
    1279                     if (omflib_add_pub (out_lib, pub_name, mod_page,
     1298                    if (omflib_add_pub (out_lib, szPubName, mod_page,
    12801299                                        lib_errmsg) != 0)
    12811300                      error (lib_errmsg);
     
    12961315                    started = TRUE;
    12971316                  }
    1298                 put_sym (name);
     1317                put_8 (cchPubName);
     1318                put_mem (szPubName, cchPubName);
    12991319                if (big)
    13001320                  put_32 (address);
     
    13311351              if (out_lib != NULL)
    13321352                {
     1353                  /* Note! make_nstr is not needed here, main is too short. */
    13331354                  if (omflib_add_pub (out_lib, name, mod_page, lib_errmsg) != 0)
    13341355                    error (lib_errmsg);
     
    24122433                         long ord, const char *mod)
    24132434{
     2435  char szPubName[256];
     2436  int  cchPubName;
     2437
    24142438  /* Skip a leading underscore character if present. */
    24152439
    24162440  if (strip_underscore (pub_name))
    24172441    ++pub_name;
     2442  cchPubName = make_nstr (pub_name, strlen (pub_name), szPubName);
    24182443
    24192444  /* Make the symbol public in the output library. */
    24202445
    2421   if (omflib_add_pub (out_lib, pub_name, mod_page, lib_errmsg) != 0)
     2446  if (omflib_add_pub (out_lib, szPubName, mod_page, lib_errmsg) != 0)
    24222447    error (lib_errmsg);
    24232448
     
    24292454  put_8 (IMPDEF_SUBTYPE);
    24302455  put_8 (proc_name == NULL ? 0x01 : 0x00); /* Import by ordinal or by name */
    2431   put_str (pub_name);           /* Underscore already removed above */
     2456  put_8 (cchPubName);
     2457  put_mem (szPubName, cchPubName);
    24322458  put_str (mod);
    24332459  if (proc_name == NULL)
     
    24352461  else if (strcmp (proc_name, pub_name) == 0)
    24362462    put_8 (0);
    2437   else
     2463  else {
    24382464    put_str (proc_name);
     2465  }
    24392466  write_rec ();
    24402467  init_rec (MODEND|REC32);
Note: See TracChangeset for help on using the changeset viewer.