Reduce warnings, adjust format strings in util/led

Calls like `debug("something\n", 0, 0, 0, 0)` cause clang warnings,
because debug() is a macro that passes its arguments to printf(), and
clang warns about extra 0s to printf().  Silence the warnings by
hiding the printf() in a new function do_debug().  The code still
passes extra 0s to printf(), but clang can't warn.

Macros debug() and verbose() should use C99 __VA_ARGS__, so they don't
require the extra 0s; but ACK doesn't use __VA_ARGS__ yet.

Adjust some format strings for debug() or fatal(), or cast their
arguments, to match their types.  I don't know whether uint32_t is
unsigned int or unsigned long, so I cast it to unsigned long, and
print it with "%lx".

In util/led/sym.c, #include "save.h" to declare savechar(), and use
parentheses to silence a clang warning in hash().
This commit is contained in:
George Koehler 2019-11-01 18:27:34 -04:00
parent 17bc9cdef7
commit 3f3bf1e164
6 changed files with 28 additions and 12 deletions

View file

@ -7,6 +7,7 @@
#ifndef __DEBUG_H_INCLUDED__ #ifndef __DEBUG_H_INCLUDED__
#define __DEBUG_H_INCLUDED__ #define __DEBUG_H_INCLUDED__
#include "error.h"
#ifdef NDEBUG #ifdef NDEBUG
@ -15,13 +16,11 @@
#else #else
extern int DEB; extern int DEB;
#define debug(s, a1, a2, a3, a4) (DEB && printf(s, a1, a2, a3, a4)) #define debug(s, a1, a2, a3, a4) (DEB && do_debug(s, a1, a2, a3, a4))
#endif #endif
extern int Verbose; extern int Verbose;
#define verbose(s, a1, a2, a3, a4) (Verbose && do_verbose(s, a1, a2, a3, a4)) #define verbose(s, a1, a2, a3, a4) (Verbose && do_verbose(s, a1, a2, a3, a4))
extern void fatal(char* format, ...);
#endif /* __DEBUG_H_INCLUDED__ */ #endif /* __DEBUG_H_INCLUDED__ */

View file

@ -60,6 +60,17 @@ void error(char *format, ...)
va_end(ap); va_end(ap);
} }
/* VARARGS1 */
int do_debug(char *format, ...)
{
/* printf() and return 1 */
va_list ap;
va_start(ap, format);
vprintf(format, ap);
va_end(ap);
return 1;
}
/* VARARGS1 */ /* VARARGS1 */
int do_verbose(char *format, ...) int do_verbose(char *format, ...)
{ {

View file

@ -13,6 +13,7 @@ void stop(void);
void fatal(char *format, ...); void fatal(char *format, ...);
void warning(char *format, ...); void warning(char *format, ...);
void error(char *format, ...); void error(char *format, ...);
int do_debug(char *format, ...);
int do_verbose(char *format, ...); int do_verbose(char *format, ...);

View file

@ -580,7 +580,7 @@ void addbase(struct outname *name)
address((name->on_type & S_EXT) ? ALLOGCHR : ALLOLCHR, address((name->on_type & S_EXT) ? ALLOGCHR : ALLOLCHR,
(ind_t)name->on_foff (ind_t)name->on_foff
), ),
name->on_type, name->on_valu, 0 name->on_type, (unsigned long)name->on_valu, 0
); );
} }

View file

@ -416,7 +416,8 @@ static void put_mips_valu(char* addr, uint32_t value)
/* The two bottom zero bits are implicit. */ /* The two bottom zero bits are implicit. */
if (value & 3) if (value & 3)
fatal("invalid MIPS relocation value 0x%x", value); fatal("invalid MIPS relocation value 0x%lx",
(unsigned long)value);
value >>= 2; value >>= 2;
switch (opcode >> 26) switch (opcode >> 26)
@ -560,7 +561,8 @@ void relocate(struct outhead *head, char* emit, struct outname names[], struct o
* Pick up previous value at location to be relocated. * Pick up previous value at location to be relocated.
*/ */
valu = getvalu(emit + (relo->or_addr - off), relo->or_type); valu = getvalu(emit + (relo->or_addr - off), relo->or_type);
debug("read relocation from 0x%08x type 0x%x value 0x%08x symbol %d\n", realaddress, relo->or_type, valu, relo->or_nami); debug("read relocation from 0x%08lx type 0x%x value 0x%08lx symbol %u\n",
(unsigned long)realaddress, relo->or_type, valu, relo->or_nami);
/* /*
* Or_nami is an index in the name table of the considered module. * Or_nami is an index in the name table of the considered module.
@ -595,7 +597,8 @@ void relocate(struct outhead *head, char* emit, struct outname names[], struct o
/* /*
* Now put the value back. * Now put the value back.
*/ */
debug("written fixed up relocation to 0x%08x type 0x%x value 0x%08x\n", realaddress, relo->or_type, valu, 0); debug("written fixed up relocation to 0x%08lx type 0x%x value 0x%08lx\n",
(unsigned long)realaddress, relo->or_type, valu, 0);
putvalu(valu, emit + (relo->or_addr - off), relo->or_type); putvalu(valu, emit + (relo->or_addr - off), relo->or_type);
/* /*

View file

@ -19,6 +19,7 @@ static char rcsid[] = "$Id$";
#include "error.h" #include "error.h"
#include "memory.h" #include "memory.h"
#include "debug.h" #include "debug.h"
#include "save.h"
#include "sym.h" #include "sym.h"
/* /*
@ -66,7 +67,8 @@ struct outname *searchname(char *string, int hashval)
register struct symbol *sym; register struct symbol *sym;
symindex = hashtable[hashval]; symindex = hashtable[hashval];
debug("looking for %s %d %ld:", string, hashval, hashtable[hashval], 0); debug("looking for %s %d %z:", string, hashval,
(size_t)hashtable[hashval], 0);
while (symindex != BADOFF) { while (symindex != BADOFF) {
sym = (struct symbol *)address(ALLOSYMB, symindex); sym = (struct symbol *)address(ALLOSYMB, symindex);
name = (struct outname *)address(ALLOGLOB, sym->sy_name); name = (struct outname *)address(ALLOGLOB, sym->sy_name);
@ -76,7 +78,8 @@ struct outname *searchname(char *string, int hashval)
while (*rcp == *namestring++) while (*rcp == *namestring++)
if (*rcp++ == '\0') { if (*rcp++ == '\0') {
debug("found %x, %x, %lx\n", debug("found %x, %x, %lx\n",
name->on_type, name->on_desc, name->on_valu, 0); name->on_type, name->on_desc,
(unsigned long)name->on_valu, 0);
return name; return name;
} }
symindex = sym->sy_next; symindex = sym->sy_next;
@ -99,12 +102,11 @@ void entername(struct outname* name, int hashval)
ind_t namindex; ind_t namindex;
register struct symbol *sym; register struct symbol *sym;
struct outname *newname; struct outname *newname;
extern ind_t savechar();
debug("entername %s %d %x %x", modulptr((ind_t)name->on_foff), hashval, name->on_type, name->on_desc); debug("entername %s %d %x %x", modulptr((ind_t)name->on_foff), hashval, name->on_type, name->on_desc);
savindex = savechar(ALLOGCHR, (ind_t)name->on_foff); savindex = savechar(ALLOGCHR, (ind_t)name->on_foff);
symindex = hard_alloc(ALLOSYMB, (long)sizeof(struct symbol)); symindex = hard_alloc(ALLOSYMB, (long)sizeof(struct symbol));
debug("; %ld\n", symindex, 0, 0, 0); debug("; %z\n", (size_t)symindex, 0, 0, 0);
namindex = hard_alloc(ALLOGLOB, (long)sizeof(struct outname)); namindex = hard_alloc(ALLOGLOB, (long)sizeof(struct outname));
if (savindex == BADOFF || symindex == BADOFF || namindex == BADOFF) if (savindex == BADOFF || symindex == BADOFF || namindex == BADOFF)
fatal("symbol table overflow"); fatal("symbol table overflow");
@ -137,7 +139,7 @@ int hash(register char* p)
register unsigned short h = 0; register unsigned short h = 0;
register int c; register int c;
while (c = *p++) { while ((c = *p++) != '\0') {
h <<= 2; h <<= 2;
h += c; h += c;
} }