1 /* $NetBSD: chk.c,v 1.9 2000/06/14 06:49:23 cgd Exp $ */ 2 3 /* 4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 5 * Copyright (c) 1994, 1995 Jochen Pohl 6 * All Rights Reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Jochen Pohl for 19 * The NetBSD Project. 20 * 4. The name of the author may not be used to endorse or promote products 21 * derived from this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #include <sys/cdefs.h> 36 #ifndef lint 37 __RCSID("$NetBSD: chk.c,v 1.9 2000/06/14 06:49:23 cgd Exp $"); 38 #endif 39 40 #include <stdlib.h> 41 #include <ctype.h> 42 #include <limits.h> 43 #include <err.h> 44 45 #include "lint2.h" 46 47 /* various type information */ 48 ttab_t ttab[NTSPEC]; 49 50 51 static void chkund __P((hte_t *)); 52 static void chkdnu __P((hte_t *)); 53 static void chkdnud __P((hte_t *)); 54 static void chkmd __P((hte_t *)); 55 static void chkvtui __P((hte_t *, sym_t *, sym_t *)); 56 static void chkvtdi __P((hte_t *, sym_t *, sym_t *)); 57 static void chkfaui __P((hte_t *, sym_t *, sym_t *)); 58 static void chkau __P((hte_t *, int, sym_t *, sym_t *, pos_t *, 59 fcall_t *, fcall_t *, type_t *, type_t *)); 60 static void chkrvu __P((hte_t *, sym_t *)); 61 static void chkadecl __P((hte_t *, sym_t *, sym_t *)); 62 static void printflike __P((hte_t *,fcall_t *, int, 63 const char *, type_t **)); 64 static void scanflike __P((hte_t *, fcall_t *, int, 65 const char *, type_t **)); 66 static void badfmt __P((hte_t *, fcall_t *)); 67 static void inconarg __P((hte_t *, fcall_t *, int)); 68 static void tofewarg __P((hte_t *, fcall_t *)); 69 static void tomanyarg __P((hte_t *, fcall_t *)); 70 static int eqtype __P((type_t *, type_t *, int, int, int, int *)); 71 static int eqargs __P((type_t *, type_t *, int *)); 72 static int mnoarg __P((type_t *, int *)); 73 74 75 void 76 inittyp() 77 { 78 int i; 79 static struct { 80 tspec_t it_tspec; 81 ttab_t it_ttab; 82 } ittab[] = { 83 { SIGNED, { 0, 0, 84 SIGNED, UNSIGN, 85 0, 0, 0, 0, 0, "signed" } }, 86 { UNSIGN, { 0, 0, 87 SIGNED, UNSIGN, 88 0, 0, 0, 0, 0, "unsigned" } }, 89 { CHAR, { CHAR_BIT, CHAR_BIT, 90 SCHAR, UCHAR, 91 1, 0, 0, 1, 1, "char" } }, 92 { SCHAR, { CHAR_BIT, CHAR_BIT, 93 SCHAR, UCHAR, 94 1, 0, 0, 1, 1, "signed char" } }, 95 { UCHAR, { CHAR_BIT, CHAR_BIT, 96 SCHAR, UCHAR, 97 1, 1, 0, 1, 1, "unsigned char" } }, 98 { SHORT, { sizeof (short) * CHAR_BIT, 2 * CHAR_BIT, 99 SHORT, USHORT, 100 1, 0, 0, 1, 1, "short" } }, 101 { USHORT, { sizeof (u_short) * CHAR_BIT, 2 * CHAR_BIT, 102 SHORT, USHORT, 103 1, 1, 0, 1, 1, "unsigned short" } }, 104 { INT, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT, 105 INT, UINT, 106 1, 0, 0, 1, 1, "int" } }, 107 { UINT, { sizeof (u_int) * CHAR_BIT, 3 * CHAR_BIT, 108 INT, UINT, 109 1, 1, 0, 1, 1, "unsigned int" } }, 110 { LONG, { sizeof (long) * CHAR_BIT, 4 * CHAR_BIT, 111 LONG, ULONG, 112 1, 0, 0, 1, 1, "long" } }, 113 { ULONG, { sizeof (u_long) * CHAR_BIT, 4 * CHAR_BIT, 114 LONG, ULONG, 115 1, 1, 0, 1, 1, "unsigned long" } }, 116 { QUAD, { sizeof (quad_t) * CHAR_BIT, 8 * CHAR_BIT, 117 QUAD, UQUAD, 118 1, 0, 0, 1, 1, "long long" } }, 119 { UQUAD, { sizeof (u_quad_t) * CHAR_BIT, 8 * CHAR_BIT, 120 QUAD, UQUAD, 121 1, 1, 0, 1, 1, "unsigned long long" } }, 122 { FLOAT, { sizeof (float) * CHAR_BIT, 4 * CHAR_BIT, 123 FLOAT, FLOAT, 124 0, 0, 1, 1, 1, "float" } }, 125 { DOUBLE, { sizeof (double) * CHAR_BIT, 8 * CHAR_BIT, 126 DOUBLE, DOUBLE, 127 0, 0, 1, 1, 1, "double" } }, 128 { LDOUBLE, { sizeof (ldbl_t) * CHAR_BIT, 10 * CHAR_BIT, 129 LDOUBLE, LDOUBLE, 130 0, 0, 1, 1, 1, "long double" } }, 131 { VOID, { -1, -1, 132 VOID, VOID, 133 0, 0, 0, 0, 0, "void" } }, 134 { STRUCT, { -1, -1, 135 STRUCT, STRUCT, 136 0, 0, 0, 0, 0, "struct" } }, 137 { UNION, { -1, -1, 138 UNION, UNION, 139 0, 0, 0, 0, 0, "union" } }, 140 { ENUM, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT, 141 ENUM, ENUM, 142 1, 0, 0, 1, 1, "enum" } }, 143 { PTR, { sizeof (void *) * CHAR_BIT, 4 * CHAR_BIT, 144 PTR, PTR, 145 0, 1, 0, 0, 1, "pointer" } }, 146 { ARRAY, { -1, -1, 147 ARRAY, ARRAY, 148 0, 0, 0, 0, 0, "array" } }, 149 { FUNC, { -1, -1, 150 FUNC, FUNC, 151 0, 0, 0, 0, 0, "function" } }, 152 }; 153 154 for (i = 0; i < sizeof (ittab) / sizeof (ittab[0]); i++) 155 STRUCT_ASSIGN(ttab[ittab[i].it_tspec], ittab[i].it_ttab); 156 if (!pflag) { 157 for (i = 0; i < NTSPEC; i++) 158 ttab[i].tt_psz = ttab[i].tt_sz; 159 } 160 } 161 162 163 /* 164 * If there is a symbol named "main", mark it as used. 165 */ 166 void 167 mainused() 168 { 169 hte_t *hte; 170 171 if ((hte = hsearch("main", 0)) != NULL) 172 hte->h_used = 1; 173 } 174 175 /* 176 * Performs all tests for a single name 177 */ 178 void 179 chkname(hte) 180 hte_t *hte; 181 { 182 sym_t *sym, *def, *pdecl, *decl; 183 184 if (uflag) { 185 chkund(hte); 186 chkdnu(hte); 187 if (xflag) 188 chkdnud(hte); 189 } 190 chkmd(hte); 191 192 /* Get definition, prototype declaration and declaration */ 193 def = pdecl = decl = NULL; 194 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) { 195 if (def == NULL && (sym->s_def == DEF || sym->s_def == TDEF)) 196 def = sym; 197 if (pdecl == NULL && sym->s_def == DECL && 198 TP(sym->s_type)->t_tspec == FUNC && 199 TP(sym->s_type)->t_proto) { 200 pdecl = sym; 201 } 202 if (decl == NULL && sym->s_def == DECL) 203 decl = sym; 204 } 205 206 /* A prototype is better than an old style declaration. */ 207 if (pdecl != NULL) 208 decl = pdecl; 209 210 chkvtui(hte, def, decl); 211 212 chkvtdi(hte, def, decl); 213 214 chkfaui(hte, def, decl); 215 216 chkrvu(hte, def); 217 218 chkadecl(hte, def, decl); 219 } 220 221 /* 222 * Print a warning if the name has been used, but not defined. 223 */ 224 static void 225 chkund(hte) 226 hte_t *hte; 227 { 228 fcall_t *fcall; 229 usym_t *usym; 230 231 if (!hte->h_used || hte->h_def) 232 return; 233 234 if ((fcall = hte->h_calls) != NULL) { 235 /* %s used( %s ), but not defined */ 236 msg(0, hte->h_name, mkpos(&fcall->f_pos)); 237 } else if ((usym = hte->h_usyms) != NULL) { 238 /* %s used( %s ), but not defined */ 239 msg(0, hte->h_name, mkpos(&usym->u_pos)); 240 } 241 } 242 243 /* 244 * Print a warning if the name has been defined, but never used. 245 */ 246 static void 247 chkdnu(hte) 248 hte_t *hte; 249 { 250 sym_t *sym; 251 252 if (!hte->h_def || hte->h_used) 253 return; 254 255 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) { 256 if (sym->s_def == DEF || sym->s_def == TDEF) { 257 /* %s defined( %s ), but never used */ 258 msg(1, hte->h_name, mkpos(&sym->s_pos)); 259 break; 260 } 261 } 262 } 263 264 /* 265 * Print a warning if the variable has been declared, but is not used 266 * or defined. 267 */ 268 static void 269 chkdnud(hte) 270 hte_t *hte; 271 { 272 sym_t *sym; 273 274 if (hte->h_syms == NULL || hte->h_used || hte->h_def) 275 return; 276 277 sym = hte->h_syms; 278 if (TP(sym->s_type)->t_tspec == FUNC) 279 return; 280 281 if (sym->s_def != DECL) 282 errx(1, "internal error: chkdnud() 1"); 283 /* %s declared( %s ), but never used or defined */ 284 msg(2, hte->h_name, mkpos(&sym->s_pos)); 285 } 286 287 /* 288 * Print a warning if there is more then one definition for 289 * this name. 290 */ 291 static void 292 chkmd(hte) 293 hte_t *hte; 294 { 295 sym_t *sym, *def1; 296 char *pos1; 297 298 if (!hte->h_def) 299 return; 300 301 def1 = NULL; 302 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) { 303 /* 304 * ANSI C allows tentative definitions of the same name in 305 * only one compilation unit. 306 */ 307 if (sym->s_def != DEF && (!sflag || sym->s_def != TDEF)) 308 continue; 309 if (def1 == NULL) { 310 def1 = sym; 311 continue; 312 } 313 pos1 = xstrdup(mkpos(&def1->s_pos)); 314 /* %s multiply defined\t%s :: %s */ 315 msg(3, hte->h_name, pos1, mkpos(&sym->s_pos)); 316 free(pos1); 317 } 318 } 319 320 /* 321 * Print a warning if the return value assumed for a function call 322 * differs from the return value of the function definition or 323 * function declaration. 324 * 325 * If no definition/declaration can be found, the assumed return values 326 * are always int. So there is no need to compare with another function 327 * call as it's done for function arguments. 328 */ 329 static void 330 chkvtui(hte, def, decl) 331 hte_t *hte; 332 sym_t *def, *decl; 333 { 334 fcall_t *call; 335 char *pos1; 336 type_t *tp1, *tp2; 337 /* LINTED (automatic hides external declaration: warn) */ 338 int warn, eq; 339 tspec_t t1; 340 341 if (hte->h_calls == NULL) 342 return; 343 344 if (def == NULL) 345 def = decl; 346 if (def == NULL) 347 return; 348 349 t1 = (tp1 = TP(def->s_type)->t_subt)->t_tspec; 350 for (call = hte->h_calls; call != NULL; call = call->f_nxt) { 351 tp2 = TP(call->f_type)->t_subt; 352 eq = eqtype(tp1, tp2, 1, 0, 0, (warn = 0, &warn)); 353 if (!call->f_rused) { 354 /* no return value used */ 355 if ((t1 == STRUCT || t1 == UNION) && !eq) { 356 /* 357 * If a function returns a struct or union it 358 * must be declared to return a struct or 359 * union, also if the return value is ignored. 360 * This is necessary because the caller must 361 * allocate stack space for the return value. 362 * If it does not, the return value would over- 363 * write other data. 364 * XXX Following massage may be confusing 365 * because it appears also if the return value 366 * was declared inconsistently. But this 367 * behaviour matches pcc based lint, so it is 368 * accepted for now. 369 */ 370 pos1 = xstrdup(mkpos(&def->s_pos)); 371 /* %s value must be decl. before use %s :: %s */ 372 msg(17, hte->h_name, 373 pos1, mkpos(&call->f_pos)); 374 free(pos1); 375 } 376 continue; 377 } 378 if (!eq || (sflag && warn)) { 379 pos1 = xstrdup(mkpos(&def->s_pos)); 380 /* %s value used inconsistenty\t%s :: %s */ 381 msg(4, hte->h_name, pos1, mkpos(&call->f_pos)); 382 free(pos1); 383 } 384 } 385 } 386 387 /* 388 * Print a warning if a definition/declaration does not match another 389 * definition/declaration of the same name. For functions, only the 390 * types of return values are tested. 391 */ 392 static void 393 chkvtdi(hte, def, decl) 394 hte_t *hte; 395 sym_t *def, *decl; 396 { 397 sym_t *sym; 398 type_t *tp1, *tp2; 399 /* LINTED (automatic hides external declaration: warn) */ 400 int eq, warn; 401 char *pos1; 402 403 if (def == NULL) 404 def = decl; 405 if (def == NULL) 406 return; 407 408 tp1 = TP(def->s_type); 409 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) { 410 if (sym == def) 411 continue; 412 tp2 = TP(sym->s_type); 413 warn = 0; 414 if (tp1->t_tspec == FUNC && tp2->t_tspec == FUNC) { 415 eq = eqtype(tp1->t_subt, tp2->t_subt, 1, 0, 0, &warn); 416 } else { 417 eq = eqtype(tp1, tp2, 0, 0, 0, &warn); 418 } 419 if (!eq || (sflag && warn)) { 420 pos1 = xstrdup(mkpos(&def->s_pos)); 421 /* %s value declared inconsistently\t%s :: %s */ 422 msg(5, hte->h_name, pos1, mkpos(&sym->s_pos)); 423 free(pos1); 424 } 425 } 426 } 427 428 /* 429 * Print a warning if a function is called with arguments which does 430 * not match the function definition, declaration or another call 431 * of the same function. 432 */ 433 static void 434 chkfaui(hte, def, decl) 435 hte_t *hte; 436 sym_t *def, *decl; 437 { 438 type_t *tp1, *tp2, **ap1, **ap2; 439 pos_t *pos1p = NULL; 440 fcall_t *calls, *call, *call1; 441 int n, as; 442 char *pos1; 443 arginf_t *ai; 444 445 if ((calls = hte->h_calls) == NULL) 446 return; 447 448 /* 449 * If we find a function definition, we use this for comparison, 450 * otherwise the first prototype we can find. If there is no 451 * definition or prototype declaration, the first function call 452 * is used. 453 */ 454 tp1 = NULL; 455 call1 = NULL; 456 if (def != NULL) { 457 if ((tp1 = TP(def->s_type))->t_tspec != FUNC) 458 return; 459 pos1p = &def->s_pos; 460 } else if (decl != NULL && TP(decl->s_type)->t_proto) { 461 if ((tp1 = TP(decl->s_type))->t_tspec != FUNC) 462 return; 463 pos1p = &decl->s_pos; 464 } 465 if (tp1 == NULL) { 466 call1 = calls; 467 calls = calls->f_nxt; 468 if ((tp1 = TP(call1->f_type))->t_tspec != FUNC) 469 return; 470 pos1p = &call1->f_pos; 471 } 472 473 n = 1; 474 for (call = calls; call != NULL; call = call->f_nxt) { 475 if ((tp2 = TP(call->f_type))->t_tspec != FUNC) 476 continue; 477 ap1 = tp1->t_args; 478 ap2 = tp2->t_args; 479 n = 0; 480 while (*ap1 != NULL && *ap2 != NULL) { 481 if (def != NULL && def->s_va && n >= def->s_nva) 482 break; 483 n++; 484 chkau(hte, n, def, decl, pos1p, call1, call, 485 *ap1, *ap2); 486 ap1++; 487 ap2++; 488 } 489 if (*ap1 == *ap2) { 490 /* equal # of arguments */ 491 } else if (def != NULL && def->s_va && n >= def->s_nva) { 492 /* 493 * function definition with VARARGS; The # of 494 * arguments of the call must be at least as large 495 * as the parameter of VARARGS. 496 */ 497 } else if (*ap2 != NULL && tp1->t_proto && tp1->t_vararg) { 498 /* 499 * prototype with ... and function call with 500 * at least the same # of arguments as declared 501 * in the prototype. 502 */ 503 } else { 504 pos1 = xstrdup(mkpos(pos1p)); 505 /* %s: variable # of args\t%s :: %s */ 506 msg(7, hte->h_name, pos1, mkpos(&call->f_pos)); 507 free(pos1); 508 continue; 509 } 510 511 /* perform SCANFLIKE/PRINTFLIKE tests */ 512 if (def == NULL || (!def->s_prfl && !def->s_scfl)) 513 continue; 514 as = def->s_prfl ? def->s_nprfl : def->s_nscfl; 515 for (ai = call->f_args; ai != NULL; ai = ai->a_nxt) { 516 if (ai->a_num == as) 517 break; 518 } 519 if (ai == NULL || !ai->a_fmt) 520 continue; 521 if (def->s_prfl) { 522 printflike(hte, call, n, ai->a_fstrg, ap2); 523 } else { 524 scanflike(hte, call, n, ai->a_fstrg, ap2); 525 } 526 } 527 } 528 529 /* 530 * Check a single argument in a function call. 531 * 532 * hte a pointer to the hash table entry of the function 533 * n the number of the argument (1..) 534 * def the function definition or NULL 535 * decl prototype declaration, old style declaration or NULL 536 * pos1p position of definition, declaration of first call 537 * call1 first call, if both def and decl are old style def/decl 538 * call checked call 539 * arg1 currently checked argument of def/decl/call1 540 * arg2 currently checked argument of call 541 * 542 */ 543 static void 544 chkau(hte, n, def, decl, pos1p, call1, call, arg1, arg2) 545 hte_t *hte; 546 int n; 547 sym_t *def, *decl; 548 pos_t *pos1p; 549 fcall_t *call1, *call; 550 type_t *arg1, *arg2; 551 { 552 /* LINTED (automatic hides external declaration: warn) */ 553 int promote, asgn, warn; 554 tspec_t t1, t2; 555 arginf_t *ai, *ai1; 556 char *pos1; 557 558 /* 559 * If a function definition is available (def != NULL), we compair the 560 * function call (call) with the definition. Otherwise, if a function 561 * definition is available and it is not an old style definition 562 * (decl != NULL && TP(decl->s_type)->t_proto), we compair the call 563 * with this declaration. Otherwise we compair it with the first 564 * call we have found (call1). 565 */ 566 567 /* arg1 must be promoted if it stems from an old style definition */ 568 promote = def != NULL && def->s_osdef; 569 570 /* 571 * If we compair with a definition or declaration, we must perform 572 * the same checks for qualifiers in indirected types as in 573 * assignments. 574 */ 575 asgn = def != NULL || (decl != NULL && TP(decl->s_type)->t_proto); 576 577 warn = 0; 578 if (eqtype(arg1, arg2, 1, promote, asgn, &warn) && (!sflag || !warn)) 579 return; 580 581 /* 582 * Other lint implementations print warnings as soon as the type 583 * of an argument does not match exactly the expected type. The 584 * result are lots of warnings which are really not neccessary. 585 * We print a warning only if 586 * (0) at least one type is not an interger type and types differ 587 * (1) hflag is set and types differ 588 * (2) types differ, except in signedness 589 * If the argument is an integer constant whose msb is not set, 590 * signedness is ignored (e.g. 0 matches both signed and unsigned 591 * int). This is with and without hflag. 592 * If the argument is an integer constant with value 0 and the 593 * expected argument is of type pointer and the width of the 594 * interger constant is the same as the width of the pointer, 595 * no warning is printed. 596 */ 597 t1 = arg1->t_tspec; 598 t2 = arg2->t_tspec; 599 if (isityp(t1) && isityp(t2) && !arg1->t_isenum && !arg2->t_isenum) { 600 if (promote) { 601 /* 602 * XXX Here is a problem: Althrough it is possible to 603 * pass an int where a char/short it expected, there 604 * may be loss in significant digits. We should first 605 * check for const arguments if they can be converted 606 * into the original parameter type. 607 */ 608 if (t1 == FLOAT) { 609 t1 = DOUBLE; 610 } else if (t1 == CHAR || t1 == SCHAR) { 611 t1 = INT; 612 } else if (t1 == UCHAR) { 613 t1 = tflag ? UINT : INT; 614 } else if (t1 == SHORT) { 615 t1 = INT; 616 } else if (t1 == USHORT) { 617 /* CONSTCOND */ 618 t1 = INT_MAX < USHRT_MAX || tflag ? UINT : INT; 619 } 620 } 621 622 if (styp(t1) == styp(t2)) { 623 624 /* 625 * types differ only in signedness; get information 626 * about arguments 627 */ 628 629 /* 630 * treat a definition like a call with variable 631 * arguments 632 */ 633 ai1 = call1 != NULL ? call1->f_args : NULL; 634 635 /* 636 * if two calls are compared, ai1 is set to the 637 * information for the n-th argument, if this was 638 * a constant, otherwise to NULL 639 */ 640 for ( ; ai1 != NULL; ai1 = ai1->a_nxt) { 641 if (ai1->a_num == n) 642 break; 643 } 644 /* 645 * ai is set to the information of the n-th arg 646 * of the (second) call, if this was a constant, 647 * otherwise to NULL 648 */ 649 for (ai = call->f_args; ai != NULL; ai = ai->a_nxt) { 650 if (ai->a_num == n) 651 break; 652 } 653 654 if (ai1 == NULL && ai == NULL) { 655 /* no constant at all */ 656 if (!hflag) 657 return; 658 } else if (ai1 == NULL || ai == NULL) { 659 /* one constant */ 660 if (ai == NULL) 661 ai = ai1; 662 if (ai->a_zero || ai->a_pcon) 663 /* same value in signed and unsigned */ 664 return; 665 /* value (not representation) differently */ 666 } else { 667 /* 668 * two constants, one signed, one unsigned; 669 * if the msb of one of the constants is set, 670 * the argument is used inconsistently. 671 */ 672 if (!ai1->a_ncon && !ai->a_ncon) 673 return; 674 } 675 } 676 677 } else if (t1 == PTR && isityp(t2)) { 678 for (ai = call->f_args; ai != NULL; ai = ai->a_nxt) { 679 if (ai->a_num == n) 680 break; 681 } 682 /* 683 * Vendor implementations of lint (e.g. HP-UX, Digital UNIX) 684 * don't care about the size of the integer argument, 685 * only whether or not it is zero. We do the same. 686 */ 687 if (ai != NULL && ai->a_zero) 688 return; 689 } 690 691 pos1 = xstrdup(mkpos(pos1p)); 692 /* %s, arg %d used inconsistently\t%s :: %s */ 693 msg(6, hte->h_name, n, pos1, mkpos(&call->f_pos)); 694 free(pos1); 695 } 696 697 /* 698 * Compare the types in the NULL-terminated array ap with the format 699 * string fmt. 700 */ 701 static void 702 printflike(hte, call, n, fmt, ap) 703 hte_t *hte; 704 fcall_t *call; 705 int n; 706 const char *fmt; 707 type_t **ap; 708 { 709 const char *fp; 710 int fc; 711 int fwidth, prec, left, sign, space, alt, zero; 712 tspec_t sz, t1, t2 = NOTSPEC; 713 type_t *tp; 714 715 fp = fmt; 716 fc = *fp++; 717 718 for ( ; ; ) { 719 if (fc == '\0') { 720 if (*ap != NULL) 721 tomanyarg(hte, call); 722 break; 723 } 724 if (fc != '%') { 725 badfmt(hte, call); 726 break; 727 } 728 fc = *fp++; 729 fwidth = prec = left = sign = space = alt = zero = 0; 730 sz = NOTSPEC; 731 732 /* Flags */ 733 for ( ; ; ) { 734 if (fc == '-') { 735 if (left) 736 break; 737 left = 1; 738 } else if (fc == '+') { 739 if (sign) 740 break; 741 sign = 1; 742 } else if (fc == ' ') { 743 if (space) 744 break; 745 space = 1; 746 } else if (fc == '#') { 747 if (alt) 748 break; 749 alt = 1; 750 } else if (fc == '0') { 751 if (zero) 752 break; 753 zero = 1; 754 } else { 755 break; 756 } 757 fc = *fp++; 758 } 759 760 /* field width */ 761 if (isdigit(fc)) { 762 fwidth = 1; 763 do { fc = *fp++; } while (isdigit(fc)) ; 764 } else if (fc == '*') { 765 fwidth = 1; 766 fc = *fp++; 767 if ((tp = *ap++) == NULL) { 768 tofewarg(hte, call); 769 break; 770 } 771 n++; 772 if ((t1 = tp->t_tspec) != INT && (hflag || t1 != UINT)) 773 inconarg(hte, call, n); 774 } 775 776 /* precision */ 777 if (fc == '.') { 778 fc = *fp++; 779 prec = 1; 780 if (isdigit(fc)) { 781 do { fc = *fp++; } while (isdigit(fc)); 782 } else if (fc == '*') { 783 fc = *fp++; 784 if ((tp = *ap++) == NULL) { 785 tofewarg(hte, call); 786 break; 787 } 788 n++; 789 if (tp->t_tspec != INT) 790 inconarg(hte, call, n); 791 } else { 792 badfmt(hte, call); 793 break; 794 } 795 } 796 797 if (fc == 'h') { 798 sz = SHORT; 799 } else if (fc == 'l') { 800 sz = LONG; 801 } else if (fc == 'q') { 802 sz = QUAD; 803 } else if (fc == 'L') { 804 sz = LDOUBLE; 805 } 806 if (sz != NOTSPEC) 807 fc = *fp++; 808 809 if (fc == '%') { 810 if (sz != NOTSPEC || left || sign || space || 811 alt || zero || prec || fwidth) { 812 badfmt(hte, call); 813 } 814 fc = *fp++; 815 continue; 816 } 817 818 if (fc == '\0') { 819 badfmt(hte, call); 820 break; 821 } 822 823 if ((tp = *ap++) == NULL) { 824 tofewarg(hte, call); 825 break; 826 } 827 n++; 828 if ((t1 = tp->t_tspec) == PTR) 829 t2 = tp->t_subt->t_tspec; 830 831 if (fc == 'd' || fc == 'i') { 832 if (alt || sz == LDOUBLE) { 833 badfmt(hte, call); 834 break; 835 } 836 int_conv: 837 if (sz == LONG) { 838 if (t1 != LONG && (hflag || t1 != ULONG)) 839 inconarg(hte, call, n); 840 } else if (sz == QUAD) { 841 if (t1 != QUAD && (hflag || t1 != UQUAD)) 842 inconarg(hte, call, n); 843 } else { 844 /* 845 * SHORT is always promoted to INT, USHORT 846 * to INT or UINT. 847 */ 848 if (t1 != INT && (hflag || t1 != UINT)) 849 inconarg(hte, call, n); 850 } 851 } else if (fc == 'o' || fc == 'u' || fc == 'x' || fc == 'X') { 852 if ((alt && fc == 'u') || sz == LDOUBLE) 853 badfmt(hte, call); 854 uint_conv: 855 if (sz == LONG) { 856 if (t1 != ULONG && (hflag || t1 != LONG)) 857 inconarg(hte, call, n); 858 } else if (sz == QUAD) { 859 if (t1 != UQUAD && (hflag || t1 != QUAD)) 860 inconarg(hte, call, n); 861 } else if (sz == SHORT) { 862 /* USHORT was promoted to INT or UINT */ 863 if (t1 != UINT && t1 != INT) 864 inconarg(hte, call, n); 865 } else { 866 if (t1 != UINT && (hflag || t1 != INT)) 867 inconarg(hte, call, n); 868 } 869 } else if (fc == 'D' || fc == 'O' || fc == 'U') { 870 if ((alt && fc != 'O') || sz != NOTSPEC || !tflag) 871 badfmt(hte, call); 872 sz = LONG; 873 if (fc == 'D') { 874 goto int_conv; 875 } else { 876 goto uint_conv; 877 } 878 } else if (fc == 'f' || fc == 'e' || fc == 'E' || 879 fc == 'g' || fc == 'G') { 880 if (sz == NOTSPEC) 881 sz = DOUBLE; 882 if (sz != DOUBLE && sz != LDOUBLE) 883 badfmt(hte, call); 884 if (t1 != sz) 885 inconarg(hte, call, n); 886 } else if (fc == 'c') { 887 if (sz != NOTSPEC || alt || zero) 888 badfmt(hte, call); 889 if (t1 != INT) 890 inconarg(hte, call, n); 891 } else if (fc == 's') { 892 if (sz != NOTSPEC || alt || zero) 893 badfmt(hte, call); 894 if (t1 != PTR || 895 (t2 != CHAR && t2 != UCHAR && t2 != SCHAR)) { 896 inconarg(hte, call, n); 897 } 898 } else if (fc == 'p') { 899 if (fwidth || prec || sz != NOTSPEC || alt || zero) 900 badfmt(hte, call); 901 if (t1 != PTR || (hflag && t2 != VOID)) 902 inconarg(hte, call, n); 903 } else if (fc == 'n') { 904 if (fwidth || prec || alt || zero || sz == LDOUBLE) 905 badfmt(hte, call); 906 if (t1 != PTR) { 907 inconarg(hte, call, n); 908 } else if (sz == LONG) { 909 if (t2 != LONG && t2 != ULONG) 910 inconarg(hte, call, n); 911 } else if (sz == SHORT) { 912 if (t2 != SHORT && t2 != USHORT) 913 inconarg(hte, call, n); 914 } else { 915 if (t2 != INT && t2 != UINT) 916 inconarg(hte, call, n); 917 } 918 } else { 919 badfmt(hte, call); 920 break; 921 } 922 923 fc = *fp++; 924 } 925 } 926 927 /* 928 * Compare the types in the NULL-terminated array ap with the format 929 * string fmt. 930 */ 931 static void 932 scanflike(hte, call, n, fmt, ap) 933 hte_t *hte; 934 fcall_t *call; 935 int n; 936 const char *fmt; 937 type_t **ap; 938 { 939 const char *fp; 940 int fc; 941 int noasgn, fwidth; 942 tspec_t sz, t1 = NOTSPEC, t2 = NOTSPEC; 943 type_t *tp = NULL; 944 945 fp = fmt; 946 fc = *fp++; 947 948 for ( ; ; ) { 949 if (fc == '\0') { 950 if (*ap != NULL) 951 tomanyarg(hte, call); 952 break; 953 } 954 if (fc != '%') { 955 badfmt(hte, call); 956 break; 957 } 958 fc = *fp++; 959 960 noasgn = fwidth = 0; 961 sz = NOTSPEC; 962 963 if (fc == '*') { 964 noasgn = 1; 965 fc = *fp++; 966 } 967 968 if (isdigit(fc)) { 969 fwidth = 1; 970 do { fc = *fp++; } while (isdigit(fc)); 971 } 972 973 if (fc == 'h') { 974 sz = SHORT; 975 } else if (fc == 'l') { 976 sz = LONG; 977 } else if (fc == 'q') { 978 sz = QUAD; 979 } else if (fc == 'L') { 980 sz = LDOUBLE; 981 } 982 if (sz != NOTSPEC) 983 fc = *fp++; 984 985 if (fc == '%') { 986 if (sz != NOTSPEC || noasgn || fwidth) 987 badfmt(hte, call); 988 fc = *fp++; 989 continue; 990 } 991 992 if (!noasgn) { 993 if ((tp = *ap++) == NULL) { 994 tofewarg(hte, call); 995 break; 996 } 997 n++; 998 if ((t1 = tp->t_tspec) == PTR) 999 t2 = tp->t_subt->t_tspec; 1000 } 1001 1002 if (fc == 'd' || fc == 'i' || fc == 'n') { 1003 if (sz == LDOUBLE) 1004 badfmt(hte, call); 1005 if (sz != SHORT && sz != LONG && sz != QUAD) 1006 sz = INT; 1007 conv: 1008 if (!noasgn) { 1009 if (t1 != PTR) { 1010 inconarg(hte, call, n); 1011 } else if (t2 != styp(sz)) { 1012 inconarg(hte, call, n); 1013 } else if (hflag && t2 != sz) { 1014 inconarg(hte, call, n); 1015 } else if (tp->t_subt->t_const) { 1016 inconarg(hte, call, n); 1017 } 1018 } 1019 } else if (fc == 'o' || fc == 'u' || fc == 'x') { 1020 if (sz == LDOUBLE) 1021 badfmt(hte, call); 1022 if (sz == SHORT) { 1023 sz = USHORT; 1024 } else if (sz == LONG) { 1025 sz = ULONG; 1026 } else if (sz == QUAD) { 1027 sz = UQUAD; 1028 } else { 1029 sz = UINT; 1030 } 1031 goto conv; 1032 } else if (fc == 'D') { 1033 if (sz != NOTSPEC || !tflag) 1034 badfmt(hte, call); 1035 sz = LONG; 1036 goto conv; 1037 } else if (fc == 'O') { 1038 if (sz != NOTSPEC || !tflag) 1039 badfmt(hte, call); 1040 sz = ULONG; 1041 goto conv; 1042 } else if (fc == 'X') { 1043 /* 1044 * XXX valid in ANSI C, but in NetBSD's libc imple- 1045 * mented as "lx". Thats why it should be avoided. 1046 */ 1047 if (sz != NOTSPEC || !tflag) 1048 badfmt(hte, call); 1049 sz = ULONG; 1050 goto conv; 1051 } else if (fc == 'E') { 1052 /* 1053 * XXX valid in ANSI C, but in NetBSD's libc imple- 1054 * mented as "lf". Thats why it should be avoided. 1055 */ 1056 if (sz != NOTSPEC || !tflag) 1057 badfmt(hte, call); 1058 sz = DOUBLE; 1059 goto conv; 1060 } else if (fc == 'F') { 1061 /* XXX only for backward compatibility */ 1062 if (sz != NOTSPEC || !tflag) 1063 badfmt(hte, call); 1064 sz = DOUBLE; 1065 goto conv; 1066 } else if (fc == 'G') { 1067 /* 1068 * XXX valid in ANSI C, but in NetBSD's libc not 1069 * implemented 1070 */ 1071 if (sz != NOTSPEC && sz != LONG && sz != LDOUBLE) 1072 badfmt(hte, call); 1073 goto fconv; 1074 } else if (fc == 'e' || fc == 'f' || fc == 'g') { 1075 fconv: 1076 if (sz == NOTSPEC) { 1077 sz = FLOAT; 1078 } else if (sz == LONG) { 1079 sz = DOUBLE; 1080 } else if (sz != LDOUBLE) { 1081 badfmt(hte, call); 1082 sz = FLOAT; 1083 } 1084 goto conv; 1085 } else if (fc == 's' || fc == '[' || fc == 'c') { 1086 if (sz != NOTSPEC) 1087 badfmt(hte, call); 1088 if (fc == '[') { 1089 if ((fc = *fp++) == '-') { 1090 badfmt(hte, call); 1091 fc = *fp++; 1092 } 1093 if (fc != ']') { 1094 badfmt(hte, call); 1095 if (fc == '\0') 1096 break; 1097 } 1098 } 1099 if (!noasgn) { 1100 if (t1 != PTR) { 1101 inconarg(hte, call, n); 1102 } else if (t2 != CHAR && t2 != UCHAR && 1103 t2 != SCHAR) { 1104 inconarg(hte, call, n); 1105 } 1106 } 1107 } else if (fc == 'p') { 1108 if (sz != NOTSPEC) 1109 badfmt(hte, call); 1110 if (!noasgn) { 1111 if (t1 != PTR || t2 != PTR) { 1112 inconarg(hte, call, n); 1113 } else if (tp->t_subt->t_subt->t_tspec!=VOID) { 1114 if (hflag) 1115 inconarg(hte, call, n); 1116 } 1117 } 1118 } else { 1119 badfmt(hte, call); 1120 break; 1121 } 1122 1123 fc = *fp++; 1124 } 1125 } 1126 1127 static void 1128 badfmt(hte, call) 1129 hte_t *hte; 1130 fcall_t *call; 1131 { 1132 /* %s: malformed format string\t%s */ 1133 msg(13, hte->h_name, mkpos(&call->f_pos)); 1134 } 1135 1136 static void 1137 inconarg(hte, call, n) 1138 hte_t *hte; 1139 fcall_t *call; 1140 int n; 1141 { 1142 /* %s, arg %d inconsistent with format\t%s(%d) */ 1143 msg(14, hte->h_name, n, mkpos(&call->f_pos)); 1144 } 1145 1146 static void 1147 tofewarg(hte, call) 1148 hte_t *hte; 1149 fcall_t *call; 1150 { 1151 /* %s: too few args for format \t%s */ 1152 msg(15, hte->h_name, mkpos(&call->f_pos)); 1153 } 1154 1155 static void 1156 tomanyarg(hte, call) 1157 hte_t *hte; 1158 fcall_t *call; 1159 { 1160 /* %s: too many args for format \t%s */ 1161 msg(16, hte->h_name, mkpos(&call->f_pos)); 1162 } 1163 1164 1165 /* 1166 * Print warnings for return values which are used, but not returned, 1167 * or return values which are always or sometimes ignored. 1168 */ 1169 static void 1170 chkrvu(hte, def) 1171 hte_t *hte; 1172 sym_t *def; 1173 { 1174 fcall_t *call; 1175 int used, ignored; 1176 1177 if (def == NULL) 1178 /* don't know wheter or not the functions returns a value */ 1179 return; 1180 1181 if (hte->h_calls == NULL) 1182 return; 1183 1184 if (def->s_rval) { 1185 /* function has return value */ 1186 used = ignored = 0; 1187 for (call = hte->h_calls; call != NULL; call = call->f_nxt) { 1188 used |= call->f_rused || call->f_rdisc; 1189 ignored |= !call->f_rused && !call->f_rdisc; 1190 } 1191 /* 1192 * XXX as soon as we are able to disable single warnings 1193 * the following dependencies from hflag should be removed. 1194 * but for now I do'nt want to be botherd by this warnings 1195 * which are almost always useless. 1196 */ 1197 if (!used && ignored) { 1198 if (hflag) 1199 /* %s returns value which is always ignored */ 1200 msg(8, hte->h_name); 1201 } else if (used && ignored) { 1202 if (hflag) 1203 /* %s returns value which is sometimes ign. */ 1204 msg(9, hte->h_name); 1205 } 1206 } else { 1207 /* function has no return value */ 1208 for (call = hte->h_calls; call != NULL; call = call->f_nxt) { 1209 if (call->f_rused) 1210 /* %s value is used( %s ), but none ret. */ 1211 msg(10, hte->h_name, mkpos(&call->f_pos)); 1212 } 1213 } 1214 } 1215 1216 /* 1217 * Print warnings for inconsistent argument declarations. 1218 */ 1219 static void 1220 chkadecl(hte, def, decl) 1221 hte_t *hte; 1222 sym_t *def, *decl; 1223 { 1224 /* LINTED (automatic hides external declaration: warn) */ 1225 int osdef, eq, warn, n; 1226 sym_t *sym1, *sym; 1227 type_t **ap1, **ap2, *tp1, *tp2; 1228 char *pos1; 1229 const char *pos2; 1230 1231 osdef = 0; 1232 if (def != NULL) { 1233 osdef = def->s_osdef; 1234 sym1 = def; 1235 } else if (decl != NULL && TP(decl->s_type)->t_proto) { 1236 sym1 = decl; 1237 } else { 1238 return; 1239 } 1240 if (TP(sym1->s_type)->t_tspec != FUNC) 1241 return; 1242 1243 /* 1244 * XXX Prototypes should also be compared with old style function 1245 * declarations. 1246 */ 1247 1248 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) { 1249 if (sym == sym1 || !TP(sym->s_type)->t_proto) 1250 continue; 1251 ap1 = TP(sym1->s_type)->t_args; 1252 ap2 = TP(sym->s_type)->t_args; 1253 n = 0; 1254 while (*ap1 != NULL && *ap2 != NULL) { 1255 warn = 0; 1256 eq = eqtype(*ap1, *ap2, 1, osdef, 0, &warn); 1257 if (!eq || warn) { 1258 pos1 = xstrdup(mkpos(&sym1->s_pos)); 1259 pos2 = mkpos(&sym->s_pos); 1260 /* %s, arg %d declared inconsistently ... */ 1261 msg(11, hte->h_name, n + 1, pos1, pos2); 1262 free(pos1); 1263 } 1264 n++; 1265 ap1++; 1266 ap2++; 1267 } 1268 if (*ap1 == *ap2) { 1269 tp1 = TP(sym1->s_type); 1270 tp2 = TP(sym->s_type); 1271 if (tp1->t_vararg == tp2->t_vararg) 1272 continue; 1273 if (tp2->t_vararg && 1274 sym1->s_va && sym1->s_nva == n && !sflag) { 1275 continue; 1276 } 1277 } 1278 /* %s: variable # of args declared\t%s :: %s */ 1279 pos1 = xstrdup(mkpos(&sym1->s_pos)); 1280 msg(12, hte->h_name, pos1, mkpos(&sym->s_pos)); 1281 free(pos1); 1282 } 1283 } 1284 1285 1286 /* 1287 * Check compatibility of two types. Returns 1 if types are compatible, 1288 * otherwise 0. 1289 * 1290 * ignqual if set, ignore qualifiers of outhermost type; used for 1291 * function arguments 1292 * promote if set, promote left type before comparison; used for 1293 * comparisons of arguments with parameters of old style 1294 * definitions 1295 * asgn left indirected type must have at least the same qualifiers 1296 * like right indirected type (for assignments and function 1297 * arguments) 1298 * *warn set to 1 if an old style declaration was compared with 1299 * an incompatible prototype declaration 1300 */ 1301 static int 1302 eqtype(tp1, tp2, ignqual, promot, asgn, warn) 1303 type_t *tp1, *tp2; 1304 int ignqual, promot, asgn, *warn; 1305 { 1306 tspec_t t, to; 1307 int indir; 1308 1309 to = NOTSPEC; 1310 indir = 0; 1311 1312 while (tp1 != NULL && tp2 != NULL) { 1313 1314 t = tp1->t_tspec; 1315 if (promot) { 1316 if (t == FLOAT) { 1317 t = DOUBLE; 1318 } else if (t == CHAR || t == SCHAR) { 1319 t = INT; 1320 } else if (t == UCHAR) { 1321 t = tflag ? UINT : INT; 1322 } else if (t == SHORT) { 1323 t = INT; 1324 } else if (t == USHORT) { 1325 /* CONSTCOND */ 1326 t = INT_MAX < USHRT_MAX || tflag ? UINT : INT; 1327 } 1328 } 1329 1330 if (asgn && to == PTR) { 1331 if (indir == 1 && (t == VOID || tp2->t_tspec == VOID)) 1332 return (1); 1333 } 1334 1335 if (t != tp2->t_tspec) { 1336 /* 1337 * Give pointer to types which differ only in 1338 * signedness a chance if not sflag and not hflag. 1339 */ 1340 if (sflag || hflag || to != PTR) 1341 return (0); 1342 if (styp(t) != styp(tp2->t_tspec)) 1343 return (0); 1344 } 1345 1346 if (tp1->t_isenum && tp2->t_isenum) { 1347 if (tp1->t_istag && tp2->t_istag) { 1348 return (tp1->t_tag == tp2->t_tag); 1349 } else if (tp1->t_istynam && tp2->t_istynam) { 1350 return (tp1->t_tynam == tp2->t_tynam); 1351 } else if (tp1->t_isuniqpos && tp2->t_isuniqpos) { 1352 return (tp1->t_uniqpos.p_line == 1353 tp2->t_uniqpos.p_line && 1354 tp1->t_uniqpos.p_file == 1355 tp2->t_uniqpos.p_file && 1356 tp1->t_uniqpos.p_uniq == 1357 tp2->t_uniqpos.p_uniq); 1358 } else { 1359 return (0); 1360 } 1361 } 1362 1363 /* 1364 * XXX Handle combinations of enum and int if eflag is set. 1365 * But note: enum and 0 should be allowed. 1366 */ 1367 1368 if (asgn && indir == 1) { 1369 if (!tp1->t_const && tp2->t_const) 1370 return (0); 1371 if (!tp1->t_volatile && tp2->t_volatile) 1372 return (0); 1373 } else if (!ignqual && !tflag) { 1374 if (tp1->t_const != tp2->t_const) 1375 return (0); 1376 if (tp1->t_const != tp2->t_const) 1377 return (0); 1378 } 1379 1380 if (t == STRUCT || t == UNION) { 1381 if (tp1->t_istag && tp2->t_istag) { 1382 return (tp1->t_tag == tp2->t_tag); 1383 } else if (tp1->t_istynam && tp2->t_istynam) { 1384 return (tp1->t_tynam == tp2->t_tynam); 1385 } else if (tp1->t_isuniqpos && tp2->t_isuniqpos) { 1386 return (tp1->t_uniqpos.p_line == 1387 tp2->t_uniqpos.p_line && 1388 tp1->t_uniqpos.p_file == 1389 tp2->t_uniqpos.p_file && 1390 tp1->t_uniqpos.p_uniq == 1391 tp2->t_uniqpos.p_uniq); 1392 } else { 1393 return (0); 1394 } 1395 } 1396 1397 if (t == ARRAY && tp1->t_dim != tp2->t_dim) { 1398 if (tp1->t_dim != 0 && tp2->t_dim != 0) 1399 return (0); 1400 } 1401 1402 if (t == FUNC) { 1403 if (tp1->t_proto && tp2->t_proto) { 1404 if (!eqargs(tp1, tp2, warn)) 1405 return (0); 1406 } else if (tp1->t_proto) { 1407 if (!mnoarg(tp1, warn)) 1408 return (0); 1409 } else if (tp2->t_proto) { 1410 if (!mnoarg(tp2, warn)) 1411 return (0); 1412 } 1413 } 1414 1415 tp1 = tp1->t_subt; 1416 tp2 = tp2->t_subt; 1417 ignqual = promot = 0; 1418 to = t; 1419 indir++; 1420 1421 } 1422 1423 return (tp1 == tp2); 1424 } 1425 1426 /* 1427 * Compares arguments of two prototypes 1428 */ 1429 static int 1430 eqargs(tp1, tp2, warn) 1431 type_t *tp1, *tp2; 1432 int *warn; 1433 { 1434 type_t **a1, **a2; 1435 1436 if (tp1->t_vararg != tp2->t_vararg) 1437 return (0); 1438 1439 a1 = tp1->t_args; 1440 a2 = tp2->t_args; 1441 1442 while (*a1 != NULL && *a2 != NULL) { 1443 1444 if (eqtype(*a1, *a2, 1, 0, 0, warn) == 0) 1445 return (0); 1446 1447 a1++; 1448 a2++; 1449 1450 } 1451 1452 return (*a1 == *a2); 1453 } 1454 1455 /* 1456 * mnoarg() (matches functions with no argument type information) 1457 * returns 1 if all parameters of a prototype are compatible with 1458 * and old style function declaration. 1459 * This is the case if following conditions are met: 1460 * 1. the prototype must have a fixed number of parameters 1461 * 2. no parameter is of type float 1462 * 3. no parameter is converted to another type if integer promotion 1463 * is applied on it 1464 */ 1465 static int 1466 mnoarg(tp, warn) 1467 type_t *tp; 1468 int *warn; 1469 { 1470 type_t **arg; 1471 tspec_t t; 1472 1473 if (tp->t_vararg && warn != NULL) 1474 *warn = 1; 1475 for (arg = tp->t_args; *arg != NULL; arg++) { 1476 if ((t = (*arg)->t_tspec) == FLOAT) 1477 return (0); 1478 if (t == CHAR || t == SCHAR || t == UCHAR) 1479 return (0); 1480 if (t == SHORT || t == USHORT) 1481 return (0); 1482 } 1483 return (1); 1484 } 1485 1486