fix: macro table cannot contain NULL pointers (#4263).

CVS patchset: 3229
CVS date: 1999/08/16 16:18:25
This commit is contained in:
jbj 1999-08-16 16:18:25 +00:00
parent 1e4d3532ea
commit 96114b6bf2
4 changed files with 86 additions and 49 deletions

View File

@ -24,6 +24,7 @@
getopt on non-linux requires optind to be saved/restored.
- fix: don't remove file until last occurence in transaction (#4291).
- resuscitate net shared paths (#4330).
- fix: macro table cannot contain NULL pointers (#4263).
3.0.1 -> 3.0.2
- eliminate armv4 entries from rpmrc (Andrew E. Mileski).

View File

@ -101,8 +101,18 @@ expandMacroTable(MacroContext *mc)
static void
sortMacroTable(MacroContext *mc)
{
int i;
qsort(mc->macroTable, mc->firstFree, sizeof(*(mc->macroTable)),
compareMacroName);
/* Empty pointers are now at end of table. Reset first free index. */
for (i = 0; i < mc->firstFree; i++) {
if (mc->macroTable[i] != NULL)
continue;
mc->firstFree = i;
break;
}
}
void
@ -121,6 +131,7 @@ dumpMacroTable(MacroContext *mc, FILE *f)
for (i = 0; i < mc->firstFree; i++) {
MacroEntry *me;
if ((me = mc->macroTable[i]) == NULL) {
/* XXX this should never happen */
nempty++;
continue;
}
@ -554,28 +565,38 @@ static void
freeArgs(MacroBuf *mb)
{
MacroContext *mc = mb->mc;
int c;
int ndeleted = 0;
int i;
/* Delete dynamic macro definitions */
for (c = 0; c < mc->firstFree; c++) {
MacroEntry *me;
for (i = 0; i < mc->firstFree; i++) {
MacroEntry **mep, *me;
int skiptest = 0;
if ((me = mc->macroTable[c]) == NULL)
mep = &mc->macroTable[i];
me = *mep;
if (me == NULL) /* XXX this should never happen */
continue;
if (me->level < mb->depth)
continue;
if (strlen(me->name) == 1 && strchr("#*0", *me->name)) {
if (*me->name == '*' && me->used > 0)
skiptest = 1;
; /* XXX skip test for %# %* %0 */
/* XXX skip test for %# %* %0 */
} else if (!skiptest && me->used <= 0) {
#if NOTYET
rpmError(RPMERR_BADSPEC, _("Macro %%%s (%s) was not used below level %d"),
me->name, me->body, me->level);
#endif
}
popMacro(&mc->macroTable[c]);
popMacro(mep);
if (!(mep && *mep))
ndeleted++;
}
/* If any deleted macros, sort macro table */
if (ndeleted)
sortMacroTable(mc);
}
static const char *
@ -699,7 +720,7 @@ grabArgs(MacroBuf *mb, const MacroEntry *me, const char *se, char lastc)
optc++;
}
/* Add macro for each arg. Concatenate args for !* */
/* Add macro for each arg. Concatenate args for !*. */
b = be;
for (c = optind; c < argc; c++) {
sprintf(aname, "%d", (c - optind + 1));
@ -714,11 +735,11 @@ grabArgs(MacroBuf *mb, const MacroEntry *me, const char *se, char lastc)
optc++;
}
/* Add arg count as macro */
/* Add arg count as macro. */
sprintf(aname, "%d", (argc - optind));
addMacro(mb->mc, "#", NULL, aname, mb->depth);
/* Add unexpanded args as macro */
/* Add unexpanded args as macro. */
addMacro(mb->mc, "*", NULL, b, mb->depth);
return se;
@ -807,9 +828,6 @@ doFoo(MacroBuf *mb, const char *f, size_t fn, const char *g, size_t glen)
} else if (STREQ("F", f, fn)) {
b = buf + strlen(buf) + 1;
sprintf(b, "file%s.file", buf);
#if DEAD
fprintf(stderr, "FILE: \"%s\"\n", b);
#endif
}
if (b) {
@ -1194,14 +1212,14 @@ addMacro(MacroContext *mc, const char *n, const char *o, const char *b, int leve
}
void
delMacro(MacroContext *mc, const char *name)
delMacro(MacroContext *mc, const char *n)
{
MacroEntry **mep;
if (mc == NULL)
mc = &globalMacroContext;
/* If name exists, pop entry */
if ((mep = findEntry(mc, name, 0)) != NULL) {
if ((mep = findEntry(mc, n, 0)) != NULL) {
popMacro(mep);
/* If deleted name, sort macro table */
if (!(mep && *mep))
@ -1498,7 +1516,7 @@ main(int argc, char *argv[])
fclose(fp);
}
while(fgets(buf, sizeof(buf), stdin)) {
while(rdcl(buf, sizeof(buf), stdin, 1)) {
buf[strlen(buf)-1] = '\0';
x = expandMacros(NULL, NULL, buf, sizeof(buf));
fprintf(stderr, "%d->%s\n <-\n", x, buf);

View File

@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 1999-08-15 15:09-0400\n"
"POT-Creation-Date: 1999-08-16 12:06-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -2278,83 +2278,83 @@ msgstr ""
msgid "cannot read header at %d for lookup"
msgstr ""
#: ../lib/macro.c:136
#: ../lib/macro.c:146
#, c-format
msgid "======================== active %d empty %d\n"
msgstr ""
#. XXX just in case
#: ../lib/macro.c:225
#: ../lib/macro.c:235
#, c-format
msgid "%3d>%*s(empty)"
msgstr ""
#: ../lib/macro.c:260
#: ../lib/macro.c:270
#, c-format
msgid "%3d<%*s(empty)\n"
msgstr ""
#: ../lib/macro.c:433
#: ../lib/macro.c:443
msgid "Macro %%%s has unterminated body"
msgstr ""
#: ../lib/macro.c:459
#: ../lib/macro.c:469
msgid "Macro %%%s has illegal name (%%define)"
msgstr ""
#: ../lib/macro.c:465
#: ../lib/macro.c:475
msgid "Macro %%%s has unterminated opts"
msgstr ""
#: ../lib/macro.c:470
#: ../lib/macro.c:480
msgid "Macro %%%s has empty body"
msgstr ""
#: ../lib/macro.c:475
#: ../lib/macro.c:485
msgid "Macro %%%s failed to expand"
msgstr ""
#: ../lib/macro.c:500
#: ../lib/macro.c:510
msgid "Macro %%%s has illegal name (%%undefine)"
msgstr ""
#: ../lib/macro.c:573
#: ../lib/macro.c:586
msgid "Macro %%%s (%s) was not used below level %d"
msgstr ""
#: ../lib/macro.c:664
#: ../lib/macro.c:683
#, c-format
msgid "Unknown option %c in %s(%s)"
msgstr ""
#: ../lib/macro.c:839
#: ../lib/macro.c:858
#, c-format
msgid "Recursion depth(%d) greater than max(%d)"
msgstr ""
#: ../lib/macro.c:905 ../lib/macro.c:921
#: ../lib/macro.c:924 ../lib/macro.c:940
#, c-format
msgid "Unterminated %c: %s"
msgstr ""
#: ../lib/macro.c:961
#: ../lib/macro.c:980
msgid "A %% is followed by an unparseable macro"
msgstr ""
#: ../lib/macro.c:1084
#: ../lib/macro.c:1103
msgid "Macro %%%.*s not found, skipping"
msgstr ""
#: ../lib/macro.c:1165
#: ../lib/macro.c:1184
msgid "Target buffer overflow"
msgstr ""
#: ../lib/macro.c:1312 ../lib/macro.c:1320
#: ../lib/macro.c:1331 ../lib/macro.c:1339
#, c-format
msgid "File %s: %s"
msgstr ""
#: ../lib/macro.c:1323
#: ../lib/macro.c:1342
#, c-format
msgid "File %s is smaller than %d bytes"
msgstr ""

View File

@ -101,8 +101,18 @@ expandMacroTable(MacroContext *mc)
static void
sortMacroTable(MacroContext *mc)
{
int i;
qsort(mc->macroTable, mc->firstFree, sizeof(*(mc->macroTable)),
compareMacroName);
/* Empty pointers are now at end of table. Reset first free index. */
for (i = 0; i < mc->firstFree; i++) {
if (mc->macroTable[i] != NULL)
continue;
mc->firstFree = i;
break;
}
}
void
@ -121,6 +131,7 @@ dumpMacroTable(MacroContext *mc, FILE *f)
for (i = 0; i < mc->firstFree; i++) {
MacroEntry *me;
if ((me = mc->macroTable[i]) == NULL) {
/* XXX this should never happen */
nempty++;
continue;
}
@ -554,28 +565,38 @@ static void
freeArgs(MacroBuf *mb)
{
MacroContext *mc = mb->mc;
int c;
int ndeleted = 0;
int i;
/* Delete dynamic macro definitions */
for (c = 0; c < mc->firstFree; c++) {
MacroEntry *me;
for (i = 0; i < mc->firstFree; i++) {
MacroEntry **mep, *me;
int skiptest = 0;
if ((me = mc->macroTable[c]) == NULL)
mep = &mc->macroTable[i];
me = *mep;
if (me == NULL) /* XXX this should never happen */
continue;
if (me->level < mb->depth)
continue;
if (strlen(me->name) == 1 && strchr("#*0", *me->name)) {
if (*me->name == '*' && me->used > 0)
skiptest = 1;
; /* XXX skip test for %# %* %0 */
/* XXX skip test for %# %* %0 */
} else if (!skiptest && me->used <= 0) {
#if NOTYET
rpmError(RPMERR_BADSPEC, _("Macro %%%s (%s) was not used below level %d"),
me->name, me->body, me->level);
#endif
}
popMacro(&mc->macroTable[c]);
popMacro(mep);
if (!(mep && *mep))
ndeleted++;
}
/* If any deleted macros, sort macro table */
if (ndeleted)
sortMacroTable(mc);
}
static const char *
@ -699,7 +720,7 @@ grabArgs(MacroBuf *mb, const MacroEntry *me, const char *se, char lastc)
optc++;
}
/* Add macro for each arg. Concatenate args for !* */
/* Add macro for each arg. Concatenate args for !*. */
b = be;
for (c = optind; c < argc; c++) {
sprintf(aname, "%d", (c - optind + 1));
@ -714,11 +735,11 @@ grabArgs(MacroBuf *mb, const MacroEntry *me, const char *se, char lastc)
optc++;
}
/* Add arg count as macro */
/* Add arg count as macro. */
sprintf(aname, "%d", (argc - optind));
addMacro(mb->mc, "#", NULL, aname, mb->depth);
/* Add unexpanded args as macro */
/* Add unexpanded args as macro. */
addMacro(mb->mc, "*", NULL, b, mb->depth);
return se;
@ -807,9 +828,6 @@ doFoo(MacroBuf *mb, const char *f, size_t fn, const char *g, size_t glen)
} else if (STREQ("F", f, fn)) {
b = buf + strlen(buf) + 1;
sprintf(b, "file%s.file", buf);
#if DEAD
fprintf(stderr, "FILE: \"%s\"\n", b);
#endif
}
if (b) {
@ -1194,14 +1212,14 @@ addMacro(MacroContext *mc, const char *n, const char *o, const char *b, int leve
}
void
delMacro(MacroContext *mc, const char *name)
delMacro(MacroContext *mc, const char *n)
{
MacroEntry **mep;
if (mc == NULL)
mc = &globalMacroContext;
/* If name exists, pop entry */
if ((mep = findEntry(mc, name, 0)) != NULL) {
if ((mep = findEntry(mc, n, 0)) != NULL) {
popMacro(mep);
/* If deleted name, sort macro table */
if (!(mep && *mep))
@ -1498,7 +1516,7 @@ main(int argc, char *argv[])
fclose(fp);
}
while(fgets(buf, sizeof(buf), stdin)) {
while(rdcl(buf, sizeof(buf), stdin, 1)) {
buf[strlen(buf)-1] = '\0';
x = expandMacros(NULL, NULL, buf, sizeof(buf));
fprintf(stderr, "%d->%s\n <-\n", x, buf);