defRead: Accept usename longer than 511 char
The previous code always read in a defined size buffer and any name longer gets cut which causes issue during extraction because any collision on the truncated name causes components to get "lost". So here instead we keep a local stack buffer of 512 byte and use it if possible, but for longer string we allocate some space on the heap temporarily. Some later error processing had to be refactored a bit to make sure we can always clean-up after ourselves once we're done with the buffer. Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
This commit is contained in:
parent
a1fb779314
commit
9d3fb61cf3
|
|
@ -2176,7 +2176,8 @@ DefReadComponents(
|
|||
Transform t;
|
||||
const char *token;
|
||||
char *dptr;
|
||||
char usename[512];
|
||||
char *usename, usename_buf[512];
|
||||
int usename_len;
|
||||
int keyword, subkey;
|
||||
int processed = 0;
|
||||
|
||||
|
|
@ -2223,7 +2224,9 @@ DefReadComponents(
|
|||
|
||||
/* Get use and macro names */
|
||||
token = LefNextToken(f, TRUE);
|
||||
if (sscanf(token, "%511s", usename) != 1)
|
||||
|
||||
usename_len = strlen(token);
|
||||
if (!usename_len)
|
||||
{
|
||||
LefError(DEF_ERROR, "Bad component statement: Need "
|
||||
"use and macro names\n");
|
||||
|
|
@ -2231,6 +2234,17 @@ DefReadComponents(
|
|||
break;
|
||||
}
|
||||
|
||||
/* Use stack buffer if we can , else go for the heap */
|
||||
if (strlen(token) < sizeof(usename_buf))
|
||||
{
|
||||
strcpy(usename_buf, token);
|
||||
usename = usename_buf;
|
||||
}
|
||||
else
|
||||
{
|
||||
usename = StrDup(NULL, token);
|
||||
}
|
||||
|
||||
/* Magic prohibits slashes and commas in use names */
|
||||
/* when using the "identify" command. Removing these */
|
||||
/* restrictions (at least the slash) is quite complex, */
|
||||
|
|
@ -2274,11 +2288,18 @@ DefReadComponents(
|
|||
|
||||
/* Create a use for this celldef in the edit cell */
|
||||
/* Don't process properties for cells we could not find */
|
||||
if (defMacro == NULL)
|
||||
break;
|
||||
|
||||
if ((defMacro == NULL) || ((defUse = DBCellNewUse(defMacro, usename))
|
||||
== NULL))
|
||||
defUse = DBCellNewUse(defMacro, usename);
|
||||
|
||||
if (usename != usename_buf)
|
||||
freeMagic(usename);
|
||||
usename = NULL;
|
||||
|
||||
if (defUse == NULL)
|
||||
{
|
||||
if (defMacro != NULL) LefEndStatement(f);
|
||||
LefEndStatement(f);
|
||||
break;
|
||||
}
|
||||
DBLinkCell(defUse, rootDef);
|
||||
|
|
|
|||
Loading…
Reference in New Issue