Changeset 3706 for branches/libc-0.6/src


Ignore:
Timestamp:
Mar 16, 2011, 10:12:11 PM (14 years ago)
Author:
bird
Message:

0.6: Backported r3705: iconv.c: Use malloc instead of alloca for larger strings so we don't blow up the stack. Fixes #183.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/libc-0.6/src/emx/src/lib/locale/iconv.c

    r1834 r3706  
    158158  size_t    nonid;
    159159  UniChar  *ucs;
     160  UniChar  *pucsFree = NULL;
    160161  UniChar  *orig_ucs;
    161162  size_t    retval = 0;
     
    185186    }
    186187
    187   sl =  *in_left;
    188   ucs = (UniChar *) alloca (sl * sizeof (UniChar));
     188  sl = *in_left;
     189  if (sl <= 1024)
     190    ucs = (UniChar *) alloca (sl * sizeof (UniChar));
     191  else
     192    {
     193      pucsFree = ucs = (UniChar *) malloc (sl * sizeof (UniChar));
     194      if (!ucs)
     195        {
     196          errno = ENOMEM;
     197          return -1;
     198        }
     199    }
    189200  orig_ucs = ucs;
    190201
     
    220231    }
    221232#endif
     233  if (pucsFree)
     234      free(pucsFree);
    222235  FS_RESTORE();
    223236  return 0;
     
    240253      break;
    241254  }
     255  if (pucsFree)
     256      free(pucsFree);
    242257  FS_RESTORE();
    243258  return (size_t)(-1);
Note: See TracChangeset for help on using the changeset viewer.