error: clean up comparison of word vectors

The function wordvcmp returned -1 when either of the word vectors was
short; this made the function asymmetric. Since the function is only
used to compare two word vectors for equality, restrict it to this
particular use case.
This commit is contained in:
rillig 2023-08-26 15:18:27 +00:00
parent 1f3ad203f7
commit 08ac0fb3d4
4 changed files with 31 additions and 35 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: error.h,v 1.20 2023/08/26 14:50:53 rillig Exp $ */ /* $NetBSD: error.h,v 1.21 2023/08/26 15:18:27 rillig Exp $ */
/* /*
* Copyright (c) 1980, 1993 * Copyright (c) 1980, 1993
@ -281,6 +281,6 @@ char *substitute(char *, char, char);
bool touchfiles(int, Eptr **, int *, char ***); bool touchfiles(int, Eptr **, int *, char ***);
const char *verbform(int); const char *verbform(int);
void wordvbuild(char *, int*, char ***); void wordvbuild(char *, int*, char ***);
int wordvcmp(char **, int, char **); bool wordv_eq(char **, int, char **);
void wordvprint(FILE *, int, char **); void wordvprint(FILE *, int, char **);
char **wordvsplice(int, int, char **); char **wordvsplice(int, int, char **);

View File

@ -1,4 +1,4 @@
/* $NetBSD: input.c,v 1.20 2023/08/26 14:50:53 rillig Exp $ */ /* $NetBSD: input.c,v 1.21 2023/08/26 15:18:27 rillig Exp $ */
/* /*
* Copyright (c) 1980, 1993 * Copyright (c) 1980, 1993
@ -34,7 +34,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)input.c 8.1 (Berkeley) 6/6/93"; static char sccsid[] = "@(#)input.c 8.1 (Berkeley) 6/6/93";
#endif #endif
__RCSID("$NetBSD: input.c,v 1.20 2023/08/26 14:50:53 rillig Exp $"); __RCSID("$NetBSD: input.c,v 1.21 2023/08/26 15:18:27 rillig Exp $");
#endif /* not lint */ #endif /* not lint */
#include <stdio.h> #include <stdio.h>
@ -488,8 +488,8 @@ lint3(void)
{ {
if (cur_wordc < 3) if (cur_wordc < 3)
return C_UNKNOWN; return C_UNKNOWN;
if (wordvcmp(cur_wordv+2, 4, Lint31) == 0 if (wordv_eq(cur_wordv+2, 4, Lint31)
|| wordvcmp(cur_wordv+2, 6, Lint32) == 0) { || wordv_eq(cur_wordv+2, 6, Lint32)) {
language = INLINT; language = INLINT;
return C_NONSPEC; return C_NONSPEC;
} }
@ -526,7 +526,7 @@ f77(void)
* Warning on line %d of %s: %s * Warning on line %d of %s: %s
* Error. No assembly. * Error. No assembly.
*/ */
if (cur_wordc == 3 && wordvcmp(cur_wordv+1, 3, F77_no_ass) == 0) { if (cur_wordc == 3 && wordv_eq(cur_wordv+1, 3, F77_no_ass)) {
cur_wordc = 0; cur_wordc = 0;
return C_SYNC; return C_SYNC;
} }
@ -534,9 +534,9 @@ f77(void)
return C_UNKNOWN; return C_UNKNOWN;
if (lastchar(cur_wordv[6]) == ':' if (lastchar(cur_wordv[6]) == ':'
&& ( && (
wordvcmp(cur_wordv+1, 3, F77_fatal) == 0 wordv_eq(cur_wordv+1, 3, F77_fatal)
|| wordvcmp(cur_wordv+1, 3, F77_error) == 0 || wordv_eq(cur_wordv+1, 3, F77_error)
|| wordvcmp(cur_wordv+1, 3, F77_warning) == 0 || wordv_eq(cur_wordv+1, 3, F77_warning)
) )
) { ) {
language = INF77; language = INF77;
@ -563,11 +563,11 @@ DECL_STRINGS_5(static, Make_NotRemade,
static Errorclass static Errorclass
make(void) make(void)
{ {
if (wordvcmp(cur_wordv+1, 3, Make_Croak) == 0) { if (wordv_eq(cur_wordv+1, 3, Make_Croak)) {
language = INMAKE; language = INMAKE;
return C_SYNC; return C_SYNC;
} }
if (wordvcmp(cur_wordv+2, 5, Make_NotRemade) == 0) { if (wordv_eq(cur_wordv+2, 5, Make_NotRemade)) {
language = INMAKE; language = INMAKE;
return C_SYNC; return C_SYNC;
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: pi.c,v 1.23 2023/08/26 14:59:44 rillig Exp $ */ /* $NetBSD: pi.c,v 1.24 2023/08/26 15:18:27 rillig Exp $ */
/* /*
* Copyright (c) 1980, 1993 * Copyright (c) 1980, 1993
@ -34,7 +34,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)pi.c 8.1 (Berkeley) 6/6/93"; static char sccsid[] = "@(#)pi.c 8.1 (Berkeley) 6/6/93";
#endif #endif
__RCSID("$NetBSD: pi.c,v 1.23 2023/08/26 14:59:44 rillig Exp $"); __RCSID("$NetBSD: pi.c,v 1.24 2023/08/26 15:18:27 rillig Exp $");
#endif /* not lint */ #endif /* not lint */
#include <stdio.h> #include <stdio.h>
@ -329,10 +329,10 @@ pi(void)
int wordindex; int wordindex;
language = INPI; language = INPI;
if ((undefined = (wordvcmp(cur_wordv+2, 3, pi_und1) == 0)) if ((undefined = wordv_eq(cur_wordv+2, 3, pi_und1))
|| (undefined = (wordvcmp(cur_wordv+2, 3, pi_und2) == 0)) || (undefined = wordv_eq(cur_wordv+2, 3, pi_und2))
|| wordvcmp(cur_wordv+2, 4, pi_imp1) == 0 || wordv_eq(cur_wordv+2, 4, pi_imp1)
|| wordvcmp(cur_wordv+2, 4, pi_imp2) == 0 || wordv_eq(cur_wordv+2, 4, pi_imp2)
) { ) {
for (wordindex = undefined ? 5 : 6; for (wordindex = undefined ? 5 : 6;
wordindex <= cur_wordc; wordindex <= cur_wordc;
@ -419,10 +419,10 @@ pi(void)
structured = false; structured = false;
multiple = false; multiple = false;
if ( if (
(cur_wordc == 6 && wordvcmp(cur_wordv+1, 2, pi_Endmatched) == 0) (cur_wordc == 6 && wordv_eq(cur_wordv+1, 2, pi_Endmatched))
|| (cur_wordc == 8 && wordvcmp(cur_wordv+1, 4, pi_Inserted) == 0) || (cur_wordc == 8 && wordv_eq(cur_wordv+1, 4, pi_Inserted))
|| (multiple = (cur_wordc == 9 && wordvcmp(cur_wordv+1,6, pi_multiple) == 0)) || (multiple = (cur_wordc == 9 && wordv_eq(cur_wordv+1,6, pi_multiple)))
|| (structured = (cur_wordc == 10 && wordvcmp(cur_wordv+6,5, pi_structured) == 0)) || (structured = (cur_wordc == 10 && wordv_eq(cur_wordv+6,5, pi_structured)))
) { ) {
language = INPI; language = INPI;
nwordv = wordvsplice(2, cur_wordc, cur_wordv+1); nwordv = wordvsplice(2, cur_wordc, cur_wordv+1);

View File

@ -1,4 +1,4 @@
/* $NetBSD: subr.c,v 1.25 2023/08/26 15:07:14 rillig Exp $ */ /* $NetBSD: subr.c,v 1.26 2023/08/26 15:18:27 rillig Exp $ */
/* /*
* Copyright (c) 1980, 1993 * Copyright (c) 1980, 1993
@ -34,7 +34,7 @@
#if 0 #if 0
static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 6/6/93"; static char sccsid[] = "@(#)subr.c 8.1 (Berkeley) 6/6/93";
#endif #endif
__RCSID("$NetBSD: subr.c,v 1.25 2023/08/26 15:07:14 rillig Exp $"); __RCSID("$NetBSD: subr.c,v 1.26 2023/08/26 15:18:27 rillig Exp $");
#endif /* not lint */ #endif /* not lint */
#include <ctype.h> #include <ctype.h>
@ -347,18 +347,14 @@ wordvbuild(char *string, int *r_wordc, char ***r_wordv)
/* /*
* Compare two 0 based wordvectors * Compare two 0 based wordvectors
*/ */
int bool
wordvcmp(char **wordv1, int wordc, char **wordv2) wordv_eq(char **wordv1, int wordc, char **wordv2)
{ {
int back; for (int i = 0; i < wordc; i++)
if (wordv1[i] == NULL || wordv2[i] == NULL
for (int i = 0; i < wordc; i++) { || strcmp(wordv1[i], wordv2[i]) != 0)
if (wordv1[i] == NULL || wordv2[i] == NULL) return false;
return -1; return true;
if ((back = strcmp(wordv1[i], wordv2[i])) != 0)
return back;
}
return 0; /* they are equal */
} }
/* /*