From f3a44fc094dc5ce393e2029d3c7c6587a4b1a835 Mon Sep 17 00:00:00 2001 From: tecodev Date: Sat, 20 Dec 2008 00:34:55 +0000 Subject: [PATCH] * debugger/mcs51/break.c, debugger/mcs51/cmd.c, debugger/mcs51/simi.c, debugger/mcs51/symtab.c, support/cpp/libcpp/macro.c: fix format string errors * sim/ucsim/s51.src/timer2.cc: add clarifying parens * src/pic/device.c: partial rewrite using strtok, quieten compiler warnings, adopt SDCC coding style * as/link/hc08/lkelf.c, as/link/lkaomf51.c, as/link/lklibr.c, as/link/z80/lkgb.c, as/z80/asout.c, debugger/mcs51/cmd.c, sim/ucsim/utils.cc, src/SDCCasm.c, support/Util/dbuf_string.c, support/cpp/c-ppoutput.c, support/cpp/libcpp/lex.c, support/librarian/sdcclib.c, support/makebin/makebin.c: quieten most compiler warnings * sim/ucsim/avr.src/arith_inst.cc: quieten compiler warnings, probably fix operator precedence bug * doc/clean.mk: quieten rm if no .lyx is present git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@5293 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 25 +- as/link/hc08/lkelf.c | 9 +- as/link/lkaomf51.c | 9 +- as/link/lklibr.c | 36 +- as/link/z80/lkgb.c | 8 +- as/z80/asout.c | 2 +- debugger/mcs51/break.c | 2 +- debugger/mcs51/cmd.c | 34 +- debugger/mcs51/simi.c | 4 +- debugger/mcs51/symtab.c | 2 +- doc/clean.mk | 2 +- sim/ucsim/avr.src/arith_inst.cc | 6 +- sim/ucsim/s51.src/timer2.cc | 6 +- sim/ucsim/utils.cc | 6 +- src/SDCCasm.c | 4 +- src/pic/device.c | 692 +++++++++++++++++--------------- support/Util/dbuf_string.c | 5 +- support/cpp/c-ppoutput.c | 5 +- support/cpp/libcpp/lex.c | 8 +- support/cpp/libcpp/macro.c | 4 +- support/librarian/sdcclib.c | 18 + support/makebin/makebin.c | 13 +- 22 files changed, 527 insertions(+), 373 deletions(-) diff --git a/ChangeLog b/ChangeLog index cd9cee3a..9afc3e2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,32 @@ +2008-12-20 Raphael Neider + + * debugger/mcs51/break.c, debugger/mcs51/cmd.c, + debugger/mcs51/simi.c, debugger/mcs51/symtab.c, + support/cpp/libcpp/macro.c: fix format string errors + + * sim/ucsim/s51.src/timer2.cc: add clarifying parens + + * src/pic/device.c: partial rewrite using strtok, + quieten compiler warnings, adopt SDCC coding style + + * as/link/hc08/lkelf.c, as/link/lkaomf51.c, as/link/lklibr.c, + as/link/z80/lkgb.c, as/z80/asout.c, debugger/mcs51/cmd.c, + sim/ucsim/utils.cc, src/SDCCasm.c, support/Util/dbuf_string.c, + support/cpp/c-ppoutput.c, support/cpp/libcpp/lex.c, + support/librarian/sdcclib.c, support/makebin/makebin.c: + quieten most compiler warnings + + * sim/ucsim/avr.src/arith_inst.cc: quieten compiler warnings, + probably fix operator precedence bug + + * doc/clean.mk: quieten rm if no .lyx is present + 2008-12-19 Borut Razem * doc/sdccman.lyx, doc/random-notes.txt, doc/avr/avr_design.txt, doc/TININative.txt, doc/macro-sys-design.txt, doc/libdoc.txt, doc/README.txt, doc/test_suite_spec.lyx: - applaid patch 2446381: Dcoumentation spelling correcitons + applied patch 2446381: Dcoumentation spelling correcitons thanks to Steven Borley 2008-12-16 Raphael Neider diff --git a/as/link/hc08/lkelf.c b/as/link/hc08/lkelf.c index 3cc602fd..d37bfa51 100644 --- a/as/link/hc08/lkelf.c +++ b/as/link/hc08/lkelf.c @@ -18,6 +18,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -------------------------------------------------------------------------*/ +#include #include #include #include @@ -480,6 +481,7 @@ elfGenerateAbs (struct area *ap, listHeader * segments, listHeader * sections) Elf32_Word size; Elf32_Phdr * phdrp; Elf32_Shdr * shdrp; + size_t res; if (!ap->a_image) { @@ -537,7 +539,8 @@ elfGenerateAbs (struct area *ap, listHeader * segments, listHeader * sections) shdrp->sh_entsize = 0; listAdd (sections, shdrp); - fwrite (&ap->a_image[addr-ap->a_addr], 1, size, ofp); + res = fwrite (&ap->a_image[addr-ap->a_addr], 1, size, ofp); + assert(res == size); } } @@ -549,6 +552,7 @@ elfGenerateRel (struct area *ap, listHeader * segments, listHeader * sections) { Elf32_Phdr * phdrp; Elf32_Shdr * shdrp; + size_t res; if (!ap->a_image) { @@ -590,7 +594,8 @@ elfGenerateRel (struct area *ap, listHeader * segments, listHeader * sections) shdrp->sh_entsize = 0; listAdd (sections, shdrp); - fwrite (ap->a_image, 1, ap->a_size, ofp); + res = fwrite (ap->a_image, 1, ap->a_size, ofp); + assert(res == ap->a_size); } /*--------------------------------------------------------------------------*/ diff --git a/as/link/lkaomf51.c b/as/link/lkaomf51.c index 80284782..7a52f4ef 100644 --- a/as/link/lkaomf51.c +++ b/as/link/lkaomf51.c @@ -18,6 +18,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -------------------------------------------------------------------------*/ +#include #include #include #include @@ -199,8 +200,10 @@ void FreeAll(void) void OutputByte(unsigned char value) { + size_t res; GlobalChkSum+=value; - fwrite( &value, 1, 1, aomf51out ); + res = fwrite( &value, 1, 1, aomf51out ); + assert(res == 1); } void OutputWord(int value) @@ -567,7 +570,9 @@ void CollectInfoFromCDB(void) CurrentModule=0; /*Set the active module as the first one*/ while(!feof(CDBin)) { - fgets(buff, sizeof(buff)-1, CDBin); + char *res; + res = fgets(buff, sizeof(buff)-1, CDBin); + assert(res == buff); if(!feof(CDBin)) switch(buff[0]) { diff --git a/as/link/lklibr.c b/as/link/lklibr.c index 31d2e897..b56340a9 100644 --- a/as/link/lklibr.c +++ b/as/link/lklibr.c @@ -22,6 +22,7 @@ #define EQ(A,B) !strcmp((A),(B)) #define MAXLINE 254 /*when using fgets*/ +#include #include #include #include @@ -392,6 +393,7 @@ void LoadRel(char * libfname, FILE * libfp, char * ModName) { char str[NINPUT+2]; int state=0; + char *res; while (fgets(str, NINPUT, libfp) != NULL) { @@ -402,7 +404,8 @@ void LoadRel(char * libfname, FILE * libfp, char * ModName) case 0: if(EQ(str, "")) { - fgets(str, NINPUT, libfp); + res = fgets(str, NINPUT, libfp); + assert(res == str); str[NINPUT+1] = '\0'; chop_crlf(str); if(EQ(str, ModName)) state=1; @@ -438,7 +441,9 @@ int LoadAdb(FILE * libfp) while (fgets(str, MAXLINE, libfp) != NULL) { - str[NINPUT+1] = '\0'; + if (NINPUT < MAXLINE) + str[NINPUT+1] = '\0'; + chop_crlf(str); switch(state) { @@ -467,11 +472,13 @@ int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName) char FLine[MAXLINE+1]; int state=0; long IndexOffset=0, FileOffset; + char *res; while(!feof(libfp)) { FLine[0]=0; - fgets(FLine, MAXLINE, libfp); + res = fgets(FLine, MAXLINE, libfp); + assert(res == FLine); chop_crlf(FLine); switch(state) @@ -481,7 +488,8 @@ int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName) { /*The next line has the size of the index*/ FLine[0]=0; - fgets(FLine, MAXLINE, libfp); + res = fgets(FLine, MAXLINE, libfp); + assert(res == FLine); chop_crlf(FLine); IndexOffset=atol(FLine); state=1; @@ -493,7 +501,8 @@ int SdccLib(char * PathLib, FILE * libfp, char * DirLib, char * SymName) /*The next line has the name of the module and the offset of the corresponding embedded file in the library*/ FLine[0]=0; - fgets(FLine, MAXLINE, libfp); + res = fgets(FLine, MAXLINE, libfp); + assert(res == FLine); chop_crlf(FLine); sscanf(FLine, "%s %ld", ModName, &FileOffset); state=2; @@ -738,8 +747,11 @@ int fndsym( char *name ) for(j=0; absPath1[j]!=0; j++) absPath1[j]=tolower((unsigned char)absPath1[j]); for(j=0; absPath2[j]!=0; j++) absPath2[j]=tolower((unsigned char)absPath2[j]); #else - realpath(FirstFound->libspc, absPath1); - realpath(ThisLibr->libspc, absPath2); + char *res; + res = realpath(FirstFound->libspc, absPath1); + assert(res == absPath1); + res = realpath(ThisLibr->libspc, absPath2); + assert(res == absPath2); #endif if( !( EQ(absPath1, absPath2) && EQ(FirstFound->relfil, ThisLibr->relfil) ) ) { @@ -771,11 +783,13 @@ pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * Dir int state=0; long IndexOffset=0, FileOffset; pmlibrarysymbol ThisSym = NULL; + char *res; while(!feof(libfp)) { FLine[0]=0; - fgets(FLine, MAXLINE, libfp); + res = fgets(FLine, MAXLINE, libfp); + assert(res == FLine); chop_crlf(FLine); switch(state) @@ -785,7 +799,8 @@ pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * Dir { /*The next line has the size of the index*/ FLine[0]=0; - fgets(FLine, MAXLINE, libfp); + res = fgets(FLine, MAXLINE, libfp); + assert(res == FLine); chop_crlf(FLine); IndexOffset=atol(FLine); state=1; @@ -797,7 +812,8 @@ pmlibraryfile buildlibraryindex_SdccLib(char * PathLib, FILE * libfp, char * Dir /*The next line has the name of the module and the offset of the corresponding embedded file in the library*/ FLine[0]=0; - fgets(FLine, MAXLINE, libfp); + res = fgets(FLine, MAXLINE, libfp); + assert(res == FLine); chop_crlf(FLine); sscanf(FLine, "%s %ld", ModName, &FileOffset); state=2; diff --git a/as/link/z80/lkgb.c b/as/link/z80/lkgb.c index 55ae41ff..fca7cd1e 100644 --- a/as/link/z80/lkgb.c +++ b/as/link/z80/lkgb.c @@ -6,6 +6,7 @@ #ifdef GAMEBOY +#include #include #include #include @@ -182,8 +183,11 @@ VOID gb(int in) cart[0x014E/SEGSIZE][0x014E%SEGSIZE] = (unsigned char)((chk>>8)&0xFF); cart[0x014F/SEGSIZE][0x014F%SEGSIZE] = (unsigned char)(chk&0xFF); - for(i = 0; i < NBSEG; i++) - fwrite(cart[i], 1, SEGSIZE, ofp); + for(i = 0; i < NBSEG; i++) { + size_t res; + res = fwrite(cart[i], 1, SEGSIZE, ofp); + assert(res == SEGSIZE); + } } } diff --git a/as/z80/asout.c b/as/z80/asout.c index 5d756469..df9254e6 100644 --- a/as/z80/asout.c +++ b/as/z80/asout.c @@ -611,7 +611,7 @@ outbuf(char *s) fprintf(ofp, "T"); out(txt,(int) (txtp-txt)); fprintf(ofp, "\n"); - fprintf(ofp, s); + fprintf(ofp, "%s", s); out(rel,(int) (relp-rel)); fprintf(ofp, "\n"); } diff --git a/debugger/mcs51/break.c b/debugger/mcs51/break.c index 1cf62522..06376619 100644 --- a/debugger/mcs51/break.c +++ b/debugger/mcs51/break.c @@ -469,7 +469,7 @@ BP_CALLBACK(fexitCB) /* check main function */ if ( !strcmp(func->sym->name, "main")) { - fprintf(stdout, "Program exited with code %d.\n", simGetValue (0x82,'I',2)); + fprintf(stdout, "Program exited with code %lu.\n", simGetValue (0x82,'I',2)); return 1; } return 0; diff --git a/debugger/mcs51/cmd.c b/debugger/mcs51/cmd.c index 840a57a4..332ee2ed 100644 --- a/debugger/mcs51/cmd.c +++ b/debugger/mcs51/cmd.c @@ -21,6 +21,7 @@ what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ +#include #include "sdcdb.h" #include "symtab.h" #include "simi.h" @@ -903,7 +904,7 @@ static int cmdDisasm (char *s, context *cctxt, int args) else { if ( args > 1 ) - printf("Dump of assembler code from 0x%08x to 0x%08x:\n",saddr,eaddr); + printf("Dump of assembler code from 0x%08lx to 0x%08lx:\n",saddr,eaddr); found = 0; while ( saddr < eaddr ) { @@ -1011,11 +1012,11 @@ static int commonSetUserBp(char *s, context *cctxt, char bpType) module *modul; if (!applyToSet(modules,moduleLineWithAddr,braddr,&modul,&line)) { - fprintf(stderr,"Address 0x%08x not exists in code.\n",braddr); + fprintf(stderr,"Address 0x%08lx not exists in code.\n",braddr); } else { - Dprintf(D_break, ("commonSetUserBp: g) addr:%x \n",braddr)); + Dprintf(D_break, ("commonSetUserBp: g) addr:%lx \n",braddr)); setBreakPoint ( braddr , CODE , bpType , userBpCB , modul->c_name,line); } @@ -1409,9 +1410,12 @@ int cmdDelUserBp (char *s, context *cctxt) if (!*s ) { if (userBpPresent) { char buffer[10]; + char *res; + fprintf (stdout,"Delete all breakpoints? (y or n) "); fflush(stdout); - fgets(buffer,sizeof(buffer),stdin); + res = fgets(buffer,sizeof(buffer),stdin); + assert(res == &buffer[0]); if (toupper(buffer[0]) == 'Y') deleteUSERbp(-1); } @@ -1632,13 +1636,15 @@ int cmdRun (char *s, context *cctxt) resetHitCount(); simGo(0); } else { + char *res; fprintf(stdout, "The program being debugged has been started already.\n"); fprintf(stdout,"Start it from the beginning? (y or n) "); fflush(stdout); - fgets(buff,sizeof(buff),stdin); + res = fgets(buff,sizeof(buff),stdin); + assert(res == &buff[0]); if (toupper(buff[0]) == 'Y') { simReset(); resetHitCount(); @@ -1927,17 +1933,17 @@ static void infoRegisters( int all, context *ctxt) for ( j = 0; j < 8 ; j++ ) { val = simGetValue (j,'R',1); - fprintf(stdout," 0x%02X",val); + fprintf(stdout," 0x%02lX",val); } fprintf(stdout,"\n"); val = simGetValue (0xe0,'I',1); - fprintf(stdout,"ACC : 0x%02X %d %c\n",val,val,(isprint(val) ? val : '.')); + fprintf(stdout,"ACC : 0x%02lX %lu %c\n",val,val,(isprint(val) ? (char)val : '.')); val = simGetValue (0xf0,'I',1); - fprintf(stdout,"B : 0x%02X %d %c\n",val,val,(isprint(val) ? val : '.')); + fprintf(stdout,"B : 0x%02lX %lu %c\n",val,val,(isprint(val) ? (char)val : '.')); val = simGetValue (0x82,'I',2); - fprintf(stdout,"DPTR: 0x%04X %d\n",val,val); + fprintf(stdout,"DPTR: 0x%04lX %lu\n",val,val); val = simGetValue (0x81,'I',1); - fprintf(stdout,"SP : 0x%02X (0x%04X)\n",val,simGetValue (val-1,'B',2)); + fprintf(stdout,"SP : 0x%02lX (0x%04lX)\n",val,simGetValue (val-1,'B',2)); fprintf(stdout,"PSW : 0x%02X | CY : %c | AC : %c | OV : %c | P : %c\n", i,(i&0x80)?'1':'0',(i&0x40)?'1':'0',(i&4)?'1':'0',(i&1)?'1':'0'); if ( all ) @@ -1956,7 +1962,7 @@ static void infoRegisters( int all, context *ctxt) if (applyToSetFTrue(sfrsymbols,symWithAddr,i,'I',&sym)) { val = simGetValue (sym->addr,sym->addrspace,sym->size); - fprintf(stdout,"%s : 0x%02x",sym->name,val); + fprintf(stdout,"%s : 0x%02lx",sym->name,val); if ( !(i & 0x07 )) { for ( j = 0 ; j < 8 ; j++ ) @@ -2480,7 +2486,7 @@ static void printValBasic(symbol *sym, link *type, fprintf(stdout,"%f",v.f); else if (IS_PTR(type)) - fprintf(stdout,"0x%*x",size<<1,v.val); + fprintf(stdout,"0x%*lx",size<<1,v.val); else if (IS_INTEGRAL(type)) { @@ -2516,11 +2522,11 @@ static void printValBasic(symbol *sym, link *type, if (IS_BITVAR(etype)) fprintf(stdout,"%c",(v.val?'1':'0')); else - fprintf(stdout,"0x%0*x",size<<1,v.val); + fprintf(stdout,"0x%0*lx",size<<1,v.val); } } } else - fprintf(stdout,"0x%0*x",size<<1,v.val); + fprintf(stdout,"0x%0*lx",size<<1,v.val); } /*-----------------------------------------------------------------*/ diff --git a/debugger/mcs51/simi.c b/debugger/mcs51/simi.c index 59b58135..c44b4071 100644 --- a/debugger/mcs51/simi.c +++ b/debugger/mcs51/simi.c @@ -545,7 +545,7 @@ int simSetValue (unsigned int addr,char mem, int size, unsigned long val) s = buffer + strlen(buffer) -1; for ( i = 0 ; i < size ; i++ ) { - sprintf(s," 0x%x", val & 0xff); + sprintf(s," 0x%lx", val & 0xff); s += strlen(s); val >>= 8; } @@ -654,7 +654,7 @@ void simLoadFile (char *s) char buff[128]; sprintf(buff,"file \"%s\"\n",s); - printf(buff); + printf("%s",buff); sendSim(buff); waitForSim(500,NULL); } diff --git a/debugger/mcs51/symtab.c b/debugger/mcs51/symtab.c index 4e5165bc..5473d60e 100644 --- a/debugger/mcs51/symtab.c +++ b/debugger/mcs51/symtab.c @@ -105,7 +105,7 @@ void parseFunc (char *line) func->modName = currModName ; while(*rs && *rs != ',') rs++; rs++; - sscanf(rs,"%d,%d,%d",&i, + sscanf(rs,"%d,%d,%hd",&i, &(SPEC_INTN(func->sym->etype)), &(SPEC_BANK(func->sym->etype))); SPEC_INTRTN(func->sym->etype) = i; diff --git a/doc/clean.mk b/doc/clean.mk index c2caee07..b5cd2e7b 100644 --- a/doc/clean.mk +++ b/doc/clean.mk @@ -4,7 +4,7 @@ clean: *.pdf *.tex *.aux *.dvi *.idx *.ilg *.out\ *.ind *.log *.toc *~ \#* *.ps */*.css */*.pl *.gif core *.glo rm -rf sdcc-doc sdcc-doc.tar.bz2 - if [ "$(srcdir)" != "." ]; then rm *.lyx; fi + if [ "$(srcdir)" != "." ]; then rm -f *.lyx; fi # Deleting all files created by configuring or building the program # ----------------------------------------------------------------- diff --git a/sim/ucsim/avr.src/arith_inst.cc b/sim/ucsim/avr.src/arith_inst.cc index 06d0db9f..53f6626b 100644 --- a/sim/ucsim/avr.src/arith_inst.cc +++ b/sim/ucsim/avr.src/arith_inst.cc @@ -42,7 +42,7 @@ cl_avr::cpi_Rd_K(t_mem code) t_addr d; t_mem D, K, result, res; - d= 16+(code&0xf0)>>4; + d= 16+((code&0xf0)>>4); K= (code&0xf) | ((code&0xf00)>>8); D= ram->read(d); @@ -92,7 +92,7 @@ cl_avr::sbci_Rd_K(t_mem code) t_addr d; t_mem D, K, result, res; - d= 16+(code&0xf0)>>4; + d= 16+((code&0xf0)>>4); K= (code&0xf) | ((code&0xf00)>>8); D= ram->read(d); @@ -143,7 +143,7 @@ cl_avr::subi_Rd_K(t_mem code) t_addr d; t_mem D, K, result, res; - d= 16+(code&0xf0)>>4; + d= 16+((code&0xf0)>>4); K= (code&0xf) | ((code&0xf00)>>8); D= ram->read(d); diff --git a/sim/ucsim/s51.src/timer2.cc b/sim/ucsim/s51.src/timer2.cc index 93738acf..1f8399e2 100644 --- a/sim/ucsim/s51.src/timer2.cc +++ b/sim/ucsim/s51.src/timer2.cc @@ -151,9 +151,9 @@ cl_timer2::write(class cl_memory_cell *cell, t_mem *val) bit_t2oe) mode= T2MODE_CLKOUT; } - if (mode != oldmode || - TR && !oldtr || - !TR && oldtr) + if ((mode != oldmode) || + (TR && !oldtr) || + (!TR && oldtr)) T_edge= t2ex_edge= 0; } diff --git a/sim/ucsim/utils.cc b/sim/ucsim/utils.cc index eb648e7f..ba5f57c7 100644 --- a/sim/ucsim/utils.cc +++ b/sim/ucsim/utils.cc @@ -116,12 +116,14 @@ format_string(const char *format, ...) va_start(ap, format); #ifdef HAVE_VASPRINTF + int res; char *msg= NULL; - vasprintf(&msg, format, ap); + res = vasprintf(&msg, format, ap); return(msg); #elif defined HAVE_VSNPRINTF + int res; char *msg= (char*)malloc(80*25); - vsnprintf(msg, 80*25, format, ap); + res = vsnprintf(msg, 80*25, format, ap); return(msg); #elif defined HAVE__VSNPRINTF char *msg= (char*)malloc(80*25); diff --git a/src/SDCCasm.c b/src/SDCCasm.c index 08d37303..383c40a4 100644 --- a/src/SDCCasm.c +++ b/src/SDCCasm.c @@ -212,6 +212,7 @@ tfprintf (FILE *fp, const char *szFormat, ...) va_list ap; struct dbuf_s dbuf; size_t len; + size_t res; dbuf_init (&dbuf, INITIAL_INLINEASM); @@ -220,7 +221,8 @@ tfprintf (FILE *fp, const char *szFormat, ...) va_end (ap); len = dbuf_get_length (&dbuf); - fwrite(dbuf_get_buf (&dbuf), 1, len, fp); + res = fwrite(dbuf_get_buf (&dbuf), 1, len, fp); + assert(res == len); dbuf_destroy (&dbuf); } diff --git a/src/pic/device.c b/src/pic/device.c index 17ab6d5d..ffb95d01 100644 --- a/src/pic/device.c +++ b/src/pic/device.c @@ -51,364 +51,421 @@ static memRange *rangeRAM = NULL; /* parse a value from the configuration file */ -static int parse_config_value(char *str) +static int +parse_config_value (char *str) { - if (str[strlen(str) - 1] == 'K') - return atoi(str) * 1024; /* like "1K" */ - - else if (STRNCASECMP(str, "0x", 2) == 0) - return strtol(str+2, NULL, 16); /* like "0x400" */ - - else - return atoi(str); /* like "1024" */ + if (str[strlen (str) - 1] == 'K') + return atoi (str) * 1024; /* like "1K" */ + + else if (STRNCASECMP (str, "0x", 2) == 0) + return strtol (str+2, NULL, 16); /* like "0x400" */ + + else + return atoi (str); /* like "1024" */ } /* split a line into words */ -static int split_words(char result_word[SPLIT_WORDS_MAX][PIC14_STRING_LEN], char *str) +static int +split_words (char **result_word, char *str) { - char *pos = str; - int num_words = 0; - int ccount; - - while (*pos != '\0' && num_words < SPLIT_WORDS_MAX) { - /* remove leading spaces */ - while (isspace(*pos) || *pos == ',') - pos++; - - /* copy everything up until the first space or comma */ - for (ccount = 0; *pos != '\0' && !isspace(*pos) && *pos != ',' && ccount < PIC14_STRING_LEN-1; ccount++, pos++) - result_word[num_words][ccount] = *pos; - result_word[num_words][ccount] = '\0'; - - num_words++; - } - - return num_words; + static const char delim[] = " \f\n\r\t\v,"; + char *token; + int num_words; + + /* release previously allocated words */ + for (num_words = 0; num_words < SPLIT_WORDS_MAX; num_words++) + { + if (result_word[num_words]) + { + free (result_word[num_words]); + result_word[num_words] = NULL; + } // if + } // for + + /* split line */ + token = strtok (str, delim); + num_words = 0; + while (token && (num_words < SPLIT_WORDS_MAX)) + { + result_word[num_words] = Safe_strdup (token); + num_words++; + token = strtok (NULL, delim); + } // while + + return num_words; } /* remove annoying prefixes from the processor name */ -static char *sanitise_processor_name(char *name) +static char * +sanitise_processor_name (char *name) { - char *proc_pos = name; + char *proc_pos = name; - if (name == NULL) - return NULL; - - if (STRNCASECMP(proc_pos, "pic", 3) == 0) - proc_pos += 3; + if (name == NULL) + return NULL; - else if (tolower(*proc_pos) == 'p') - proc_pos += 1; - - return proc_pos; + if (STRNCASECMP (proc_pos, "pic", 3) == 0) + proc_pos += 3; + + else if (tolower (*proc_pos) == 'p') + proc_pos += 1; + + return proc_pos; } /* create a structure for a pic processor */ -static PIC_device *create_pic(char *pic_name, int maxram, int bankmsk, int confsiz, int program, int data, int eeprom, int io) +static PIC_device * +create_pic (char *pic_name, int maxram, int bankmsk, int confsiz, + int program, int data, int eeprom, int io) { - PIC_device *new_pic; - char *simple_pic_name = sanitise_processor_name(pic_name); - - new_pic = Safe_calloc(1, sizeof(PIC_device)); - new_pic->name = Safe_calloc(strlen(simple_pic_name)+1, sizeof(char)); - strcpy(new_pic->name, simple_pic_name); - - new_pic->defMaxRAMaddrs = maxram; - new_pic->bankMask = bankmsk; - new_pic->hasSecondConfigReg = confsiz > 1; - - new_pic->programMemSize = program; - new_pic->dataMemSize = data; - new_pic->eepromMemSize = eeprom; - new_pic->ioPins = io; + PIC_device *new_pic; + char *simple_pic_name = sanitise_processor_name (pic_name); - new_pic->ram = rangeRAM; - - Pics[num_of_supported_PICS] = new_pic; - num_of_supported_PICS++; - - return new_pic; + new_pic = Safe_calloc (1, sizeof (PIC_device)); + new_pic->name = Safe_strdup (simple_pic_name); + + new_pic->defMaxRAMaddrs = maxram; + new_pic->bankMask = bankmsk; + new_pic->hasSecondConfigReg = confsiz > 1; + + new_pic->programMemSize = program; + new_pic->dataMemSize = data; + new_pic->eepromMemSize = eeprom; + new_pic->ioPins = io; + + new_pic->ram = rangeRAM; + + Pics[num_of_supported_PICS] = new_pic; + num_of_supported_PICS++; + + return new_pic; } /* mark some registers as being duplicated across banks */ -static void register_map(int num_words, char word[SPLIT_WORDS_MAX][PIC14_STRING_LEN]) +static void +register_map (int num_words, char **word) { - memRange *r; - int pcount; - - if (num_words < 3) { - fprintf(stderr, "WARNING: not enough values in %s regmap directive\n", DEVICE_FILE_NAME); - return; - } + memRange *r; + int pcount; - for (pcount = 2; pcount < num_words; pcount++) { - r = Safe_calloc(1, sizeof(memRange)); - - r->start_address = parse_config_value(word[pcount]); - r->end_address = parse_config_value(word[pcount]); - r->alias = parse_config_value(word[1]); - r->bank = (r->start_address >> 7) & 3; - // add memRange to device entry for future lookup (sharebanks) - r->next = rangeRAM; - rangeRAM = r; - } + if (num_words < 3) + { + fprintf (stderr, "WARNING: not enough values in %s regmap directive\n", + DEVICE_FILE_NAME); + return; + } // if + + for (pcount = 2; pcount < num_words; pcount++) + { + r = Safe_calloc (1, sizeof (memRange)); + + r->start_address = parse_config_value (word[pcount]); + r->end_address = parse_config_value (word[pcount]); + r->alias = parse_config_value (word[1]); + r->bank = (r->start_address >> 7) & 3; + // add memRange to device entry for future lookup (sharebanks) + r->next = rangeRAM; + rangeRAM = r; + } // for } /* define ram areas - may be duplicated across banks */ -static void ram_map(int num_words, char word[SPLIT_WORDS_MAX][PIC14_STRING_LEN]) +static void +ram_map (int num_words, char **word) { - memRange *r; - - if (num_words < 4) { - fprintf(stderr, "WARNING: not enough values in %s memmap directive\n", DEVICE_FILE_NAME); - return; - } + memRange *r; - r = Safe_calloc(1, sizeof(memRange)); - //fprintf (stderr, "%s: %s %s %s\n", __FUNCTION__, word[1], word[2], word[3]); - - r->start_address = parse_config_value(word[1]); - r->end_address = parse_config_value(word[2]); - r->alias = parse_config_value(word[3]); - r->bank = (r->start_address >> 7) & 3; - - // add memRange to device entry for future lookup (sharebanks) - r->next = rangeRAM; - rangeRAM = r; + if (num_words < 4) + { + fprintf (stderr, "WARNING: not enough values in %s memmap directive\n", + DEVICE_FILE_NAME); + return; + } // if + + r = Safe_calloc (1, sizeof (memRange)); + //fprintf (stderr, "%s: %s %s %s\n", __FUNCTION__, word[1], word[2], word[3]); + + r->start_address = parse_config_value (word[1]); + r->end_address = parse_config_value (word[2]); + r->alias = parse_config_value (word[3]); + r->bank = (r->start_address >> 7) & 3; + + // add memRange to device entry for future lookup (sharebanks) + r->next = rangeRAM; + rangeRAM = r; } -static void setMaxRAM(int size) +static void +setMaxRAM (int size) { - maxRAMaddress = size; + maxRAMaddress = size; - if (maxRAMaddress < 0) { - fprintf(stderr, "invalid maxram 0x%x setting in %s\n", - maxRAMaddress, DEVICE_FILE_NAME); - return; - } + if (maxRAMaddress < 0) + { + fprintf (stderr, "invalid maxram 0x%x setting in %s\n", + maxRAMaddress, DEVICE_FILE_NAME); + return; + } // if } /* read the file with all the pic14 definitions and pick out the definition * for a processor if specified. if pic_name is NULL reads everything */ -static PIC_device *find_device(char *pic_name) +static PIC_device * +find_device (char *pic_name) { - FILE *pic_file; - char pic_buf[PIC14_STRING_LEN]; - char *pic_buf_pos; - int found_processor = FALSE; - int done = FALSE; - char processor_name[SPLIT_WORDS_MAX][PIC14_STRING_LEN]; - int num_processor_names = 0; - int pic_maxram = 0; - int pic_bankmsk = 0; - int pic_confsiz = 0; - int pic_program = 0; - int pic_data = 0; - int pic_eeprom = 0; - int pic_io = 0; - char *simple_pic_name; - char *dir; - char filename[512]; - int len = 512; - - /* allow abbreviations of the form "f877" - convert to "16f877" */ - simple_pic_name = sanitise_processor_name(pic_name); - num_of_supported_PICS = 0; - - /* open the piclist file */ - /* first scan all include directories */ - pic_file = NULL; - //fprintf( stderr, "%s: searching %s\n", __FUNCTION__, DEVICE_FILE_NAME ); - for (dir = setFirstItem(userIncDirsSet); - !pic_file && dir; - dir = setNextItem(userIncDirsSet)) - { - //fprintf( stderr, "searching1 %s\n", dir ); - SNPRINTF(&filename[0], len, "%s%s", dir, - DIR_SEPARATOR_STRING DEVICE_FILE_NAME); - pic_file = fopen( filename, "rt" ); - if (pic_file) break; - } // for - - for (dir = setFirstItem(includeDirsSet); - !pic_file && dir; - dir = setNextItem(includeDirsSet)) - { - //fprintf( stderr, "searching2 %s\n", dir ); - SNPRINTF(&filename[0], len, "%s%s", dir, - DIR_SEPARATOR_STRING DEVICE_FILE_NAME); - pic_file = fopen( filename, "rt" ); - if (pic_file) break; - } // for - - for (dir = setFirstItem(libDirsSet); - !pic_file && dir; - dir = setNextItem(libDirsSet)) - { - //fprintf( stderr, "searching3 %s\n", dir ); - SNPRINTF(&filename[0], len, "%s%s", dir, - DIR_SEPARATOR_STRING DEVICE_FILE_NAME); - pic_file = fopen( filename, "rt" ); - if (pic_file) break; - } // for - - for (dir = setFirstItem(libPathsSet); - !pic_file && dir; - dir = setNextItem(libPathsSet)) - { - //fprintf( stderr, "searching4 %s\n", dir ); - SNPRINTF(&filename[0], len, "%s%s", dir, - DIR_SEPARATOR_STRING DEVICE_FILE_NAME); - pic_file = fopen( filename, "rt" ); - if (pic_file) break; - } // for - - if (!pic_file) { - SNPRINTF(&filename[0], len, "%s", - DATADIR LIB_DIR_SUFFIX - DIR_SEPARATOR_STRING "pic" - DIR_SEPARATOR_STRING DEVICE_FILE_NAME); - pic_file = fopen( filename, "rt" ); - } // if - - if (pic_file == NULL) { - fprintf(stderr, "can't find %s\n", DEVICE_FILE_NAME); - return NULL; + FILE *pic_file; + char pic_buf[PIC14_STRING_LEN]; + int found_processor = FALSE; + int done = FALSE; + char **processor_name; + int num_processor_names = 0; + int pic_maxram = 0; + int pic_bankmsk = 0; + int pic_confsiz = 0; + int pic_program = 0; + int pic_data = 0; + int pic_eeprom = 0; + int pic_io = 0; + char *simple_pic_name; + char *dir; + char filename[512]; + int len = 512; + char **pic_word; + int num_pic_words; + int wcount; + + pic_word = Safe_calloc (sizeof (char *), SPLIT_WORDS_MAX); + processor_name = Safe_calloc (sizeof (char *), SPLIT_WORDS_MAX); + + /* allow abbreviations of the form "f877" - convert to "16f877" */ + simple_pic_name = sanitise_processor_name (pic_name); + num_of_supported_PICS = 0; + + /* open the piclist file */ + /* first scan all include directories */ + pic_file = NULL; + //fprintf (stderr, "%s: searching %s\n", __FUNCTION__, DEVICE_FILE_NAME); + for (dir = setFirstItem (userIncDirsSet); + !pic_file && dir; + dir = setNextItem (userIncDirsSet)) + { + //fprintf (stderr, "searching1 %s\n", dir); + SNPRINTF (&filename[0], len, "%s%s", dir, + DIR_SEPARATOR_STRING DEVICE_FILE_NAME); + pic_file = fopen (filename, "rt"); + if (pic_file) break; + } // for + + for (dir = setFirstItem (includeDirsSet); + !pic_file && dir; + dir = setNextItem (includeDirsSet)) + { + //fprintf (stderr, "searching2 %s\n", dir); + SNPRINTF (&filename[0], len, "%s%s", dir, + DIR_SEPARATOR_STRING DEVICE_FILE_NAME); + pic_file = fopen (filename, "rt"); + if (pic_file) break; + } // for + + for (dir = setFirstItem (libDirsSet); + !pic_file && dir; + dir = setNextItem (libDirsSet)) + { + //fprintf (stderr, "searching3 %s\n", dir); + SNPRINTF (&filename[0], len, "%s%s", dir, + DIR_SEPARATOR_STRING DEVICE_FILE_NAME); + pic_file = fopen (filename, "rt"); + if (pic_file) break; + } // for + + for (dir = setFirstItem (libPathsSet); + !pic_file && dir; + dir = setNextItem (libPathsSet)) + { + //fprintf (stderr, "searching4 %s\n", dir); + SNPRINTF (&filename[0], len, "%s%s", dir, + DIR_SEPARATOR_STRING DEVICE_FILE_NAME); + pic_file = fopen (filename, "rt"); + if (pic_file) break; + } // for + + if (!pic_file) + { + SNPRINTF (&filename[0], len, "%s", + DATADIR LIB_DIR_SUFFIX + DIR_SEPARATOR_STRING "pic" + DIR_SEPARATOR_STRING DEVICE_FILE_NAME); + pic_file = fopen (filename, "rt"); + } // if + + if (pic_file == NULL) + { + fprintf (stderr, "can't find %s\n", DEVICE_FILE_NAME); + return NULL; + } // if + + if (options.verbose) + printf ("Using devices from %s.\n", filename); + + /* read line by line */ + pic_buf[sizeof (pic_buf)-1] = '\0'; + while (fgets (pic_buf, sizeof (pic_buf)-1, pic_file) != NULL && !done) + { + /* strip comments */ + { + char *comment = strchr (pic_buf, '#'); + if (comment) + *comment = 0; + } + + /* split into fields */ + num_pic_words = split_words (pic_word, pic_buf); + + /* ignore comment / empty lines */ + if (num_pic_words > 0) + { + + if (STRCASECMP (pic_word[0], "processor") == 0) + { + if (pic_name == NULL) + { + int dcount; + + /* this is the mode where we read all the processors in - store the names for now */ + if (num_processor_names > 0) + { + /* store away all the previous processor definitions */ + for (dcount = 1; dcount < num_processor_names; dcount++) + { + create_pic (processor_name[dcount], pic_maxram, + pic_bankmsk, pic_confsiz, pic_program, + pic_data, pic_eeprom, pic_io); + } // for + } // if + + /* copy processor names */ + num_processor_names = num_pic_words; + for (dcount = 1; dcount < num_processor_names; dcount++) + { + processor_name[dcount] = pic_word[dcount]; + pic_word[dcount] = NULL; + } // for + } // if + else + { + /* if we've just completed reading a processor definition stop now */ + if (found_processor) + done = TRUE; + else + { + /* check if this processor name is a match */ + for (wcount = 1; wcount < num_pic_words; wcount++) + { + /* skip uninteresting prefixes */ + char *found_name = sanitise_processor_name (pic_word[wcount]); + + if (STRCASECMP (found_name, simple_pic_name) == 0) + found_processor = TRUE; + } // for + } // if + } // if + } // if + else + { + if (found_processor || pic_name == NULL) + { + /* only parse a processor section if we've found the one we want */ + if (STRCASECMP (pic_word[0], "maxram") == 0 && num_pic_words > 1) + { + pic_maxram = parse_config_value (pic_word[1]); + setMaxRAM (pic_maxram); + } // if + + else if (STRCASECMP (pic_word[0], "bankmsk") == 0 && num_pic_words > 1) + pic_bankmsk = parse_config_value (pic_word[1]); + + else if (STRCASECMP (pic_word[0], "confsiz") == 0 && num_pic_words > 1) + pic_confsiz = parse_config_value (pic_word[1]); + + else if (STRCASECMP (pic_word[0], "program") == 0 && num_pic_words > 1) + pic_program = parse_config_value (pic_word[1]); + + else if (STRCASECMP (pic_word[0], "data") == 0 && num_pic_words > 1) + pic_data = parse_config_value (pic_word[1]); + + else if (STRCASECMP (pic_word[0], "eeprom") == 0 && num_pic_words > 1) + pic_eeprom = parse_config_value (pic_word[1]); + + else if (STRCASECMP (pic_word[0], "io") == 0 && num_pic_words > 1) + pic_io = parse_config_value (pic_word[1]); + + else if (STRCASECMP (pic_word[0], "regmap") == 0 && num_pic_words > 2) + { + if (found_processor) + register_map (num_pic_words, pic_word); + } // if + + else if (STRCASECMP (pic_word[0], "memmap") == 0 && num_pic_words > 2) + { + if (found_processor) + ram_map (num_pic_words, pic_word); + } // if + + else + { + fprintf (stderr, "WARNING: %s: bad syntax `%s'\n", + DEVICE_FILE_NAME, pic_word[0]); + } // if + } // if + } // if } // if + } // while - if (options.verbose) { - printf ("Using devices from %s.\n", filename); - } // if - - /* read line by line */ - pic_buf[sizeof(pic_buf)-1] = '\0'; - while (fgets(pic_buf, sizeof(pic_buf)-1, pic_file) != NULL && !done) { - unsigned llen; - llen = strlen (pic_buf); - - /* remove trailing spaces */ - while (llen && isspace(pic_buf[llen-1])) { - pic_buf[llen-1] = '\0'; - llen--; - } - - /* remove leading spaces */ - for (pic_buf_pos = pic_buf; isspace(*pic_buf_pos); pic_buf_pos++) - {} - - /* ignore comment / empty lines */ - if (*pic_buf_pos != '\0' && *pic_buf_pos != '#') { - - /* split into fields */ - char pic_word[SPLIT_WORDS_MAX][PIC14_STRING_LEN]; - int num_pic_words; - int wcount; - - num_pic_words = split_words(pic_word, pic_buf_pos); - - if (STRCASECMP(pic_word[0], "processor") == 0) { - - if (pic_name == NULL) { - /* this is the mode where we read all the processors in - store the names for now */ - if (num_processor_names > 0) { - /* store away all the previous processor definitions */ - int dcount; - - for (dcount = 1; dcount < num_processor_names; dcount++) - create_pic(processor_name[dcount], pic_maxram, pic_bankmsk, - pic_confsiz, pic_program, pic_data, pic_eeprom, pic_io); - } - - num_processor_names = split_words(processor_name, pic_buf_pos); - } - else { - /* if we've just completed reading a processor definition stop now */ - if (found_processor) - done = TRUE; - else { - /* check if this processor name is a match */ - for (wcount = 1; wcount < num_pic_words; wcount++) { - - /* skip uninteresting prefixes */ - char *found_name = sanitise_processor_name(pic_word[wcount]); - - if (STRCASECMP(found_name, simple_pic_name) == 0) - found_processor = TRUE; - } - } - } - } - - else { - if (found_processor || pic_name == NULL) { - /* only parse a processor section if we've found the one we want */ - if (STRCASECMP(pic_word[0], "maxram") == 0 && num_pic_words > 1) { - pic_maxram = parse_config_value(pic_word[1]); - setMaxRAM(pic_maxram); - } - else if (STRCASECMP(pic_word[0], "bankmsk") == 0 && num_pic_words > 1) - pic_bankmsk = parse_config_value(pic_word[1]); - - else if (STRCASECMP(pic_word[0], "confsiz") == 0 && num_pic_words > 1) - pic_confsiz = parse_config_value(pic_word[1]); - - else if (STRCASECMP(pic_word[0], "program") == 0 && num_pic_words > 1) - pic_program = parse_config_value(pic_word[1]); - - else if (STRCASECMP(pic_word[0], "data") == 0 && num_pic_words > 1) - pic_data = parse_config_value(pic_word[1]); - - else if (STRCASECMP(pic_word[0], "eeprom") == 0 && num_pic_words > 1) - pic_eeprom = parse_config_value(pic_word[1]); - - else if (STRCASECMP(pic_word[0], "io") == 0 && num_pic_words > 1) - pic_io = parse_config_value(pic_word[1]); - - else if (STRCASECMP(pic_word[0], "regmap") == 0 && num_pic_words > 2) { - if (found_processor) - register_map(num_pic_words, pic_word); - } - else if (STRCASECMP(pic_word[0], "memmap") == 0 && num_pic_words > 2) { - if (found_processor) - ram_map(num_pic_words, pic_word); - } - else { - fprintf(stderr, "WARNING: %s: bad syntax `%s'\n", DEVICE_FILE_NAME, pic_word[0]); - } - } - } - } - } - - fclose(pic_file); - - /* if we're in read-the-lot mode then create the final processor definition */ - if (pic_name == NULL) { - - if (num_processor_names > 0) { - /* store away all the previous processor definitions */ - int dcount; - - for (dcount = 1; dcount < num_processor_names; dcount++) - create_pic(processor_name[dcount], pic_maxram, pic_bankmsk, - pic_confsiz, pic_program, pic_data, pic_eeprom, pic_io); - } - } - else { - /* in search mode */ - if (found_processor) { - /* create a new pic entry */ - return create_pic(pic_name, pic_maxram, pic_bankmsk, - pic_confsiz, pic_program, pic_data, pic_eeprom, pic_io); - } - } - - return NULL; + fclose (pic_file); + + split_words (pic_word, NULL); + free (pic_word); + + /* if we're in read-the-lot mode then create the final processor definition */ + if (pic_name == NULL) + { + if (num_processor_names > 0) + { + /* store away all the previous processor definitions */ + int dcount; + + for (dcount = 1; dcount < num_processor_names; dcount++) + { + create_pic (processor_name[dcount], pic_maxram, pic_bankmsk, + pic_confsiz, pic_program, pic_data, pic_eeprom, + pic_io); + } // for + } // if + } // if + else + { + /* in search mode */ + if (found_processor) + { + split_words (processor_name, NULL); + free (processor_name); + + /* create a new pic entry */ + return create_pic (pic_name, pic_maxram, pic_bankmsk, + pic_confsiz, pic_program, pic_data, + pic_eeprom, pic_io); + } // if + } // if + + split_words (processor_name, NULL); + free (processor_name); + + return NULL; } /*-----------------------------------------------------------------* @@ -421,7 +478,8 @@ static PIC_device *find_device(char *pic_name) * list_alias - if non-zero, print all of the supported aliases * for a device (e.g. F84, 16F84, etc...) *-----------------------------------------------------------------*/ -static void list_valid_pics(int ncols) +static void +list_valid_pics(int ncols) { int col=0,longest; int i,k,l; diff --git a/support/Util/dbuf_string.c b/support/Util/dbuf_string.c index c2de470d..61e125e4 100644 --- a/support/Util/dbuf_string.c +++ b/support/Util/dbuf_string.c @@ -282,7 +282,10 @@ dbuf_chomp (struct dbuf_s *dbuf) void dbuf_write (struct dbuf_s *dbuf, FILE *dest) { - fwrite (dbuf_get_buf (dbuf), 1, dbuf_get_length (dbuf), dest); + size_t res; + size_t len = dbuf_get_length (dbuf); + res = fwrite (dbuf_get_buf (dbuf), 1, len, dest); + assert(res == len); } diff --git a/support/cpp/c-ppoutput.c b/support/cpp/c-ppoutput.c index 90855835..812c91ad 100644 --- a/support/cpp/c-ppoutput.c +++ b/support/cpp/c-ppoutput.c @@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include #include "config.h" #include "system.h" #include "cpplib.h" @@ -193,9 +194,11 @@ scan_translation_unit_trad (cpp_reader *pfile) { while (_cpp_read_logical_line_trad (pfile)) { + size_t res; size_t len = pfile->out.cur - pfile->out.base; maybe_print_line (pfile->out.first_line); - fwrite (pfile->out.base, 1, len, print.outf); + res = fwrite (pfile->out.base, 1, len, print.outf); + assert(res == len); print.printed = 1; if (!CPP_OPTION (pfile, discard_comments)) account_for_newlines (pfile->out.base, len); diff --git a/support/cpp/libcpp/lex.c b/support/cpp/libcpp/lex.c index ab04177e..7c7c03a2 100644 --- a/support/cpp/libcpp/lex.c +++ b/support/cpp/libcpp/lex.c @@ -1782,6 +1782,8 @@ cpp_type2name (enum cpp_ttype type) void cpp_output_token (const cpp_token *token, FILE *fp) { + size_t res; + switch (TOKEN_SPELL (token)) { case SPELL_OPERATOR: @@ -1815,7 +1817,8 @@ cpp_output_token (const cpp_token *token, FILE *fp) { unsigned char buffer[10]; i += utf8_to_ucn (buffer, name + i) - 1; - fwrite (buffer, 1, 10, fp); + res = fwrite (buffer, 1, 10, fp); + assert (10 == res); } else fputc (NODE_NAME (token->val.node)[i], fp); @@ -1823,7 +1826,8 @@ cpp_output_token (const cpp_token *token, FILE *fp) break; case SPELL_LITERAL: - fwrite (token->val.str.text, 1, token->val.str.len, fp); + res = fwrite (token->val.str.text, 1, token->val.str.len, fp); + assert (token->val.str.len == res); break; case SPELL_NONE: diff --git a/support/cpp/libcpp/macro.c b/support/cpp/libcpp/macro.c index 764d5e3a..26e5f03a 100644 --- a/support/cpp/libcpp/macro.c +++ b/support/cpp/libcpp/macro.c @@ -1657,7 +1657,7 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro) function-like macros, but not at the end. */ if (following_paste_op) { - cpp_error (pfile, CPP_DL_ERROR, paste_op_error_msg); + cpp_error (pfile, CPP_DL_ERROR, "%s", paste_op_error_msg); return false; } break; @@ -1670,7 +1670,7 @@ create_iso_definition (cpp_reader *pfile, cpp_macro *macro) function-like macros, but not at the beginning. */ if (macro->count == 1) { - cpp_error (pfile, CPP_DL_ERROR, paste_op_error_msg); + cpp_error (pfile, CPP_DL_ERROR, "%s", paste_op_error_msg); return false; } diff --git a/support/librarian/sdcclib.c b/support/librarian/sdcclib.c index e8a36d61..9367f8f3 100644 --- a/support/librarian/sdcclib.c +++ b/support/librarian/sdcclib.c @@ -48,6 +48,24 @@ int NumRelFiles=0; #define EQ(A,B) !strcmp((A),(B)) #define NEQ(A,B) strcmp((A),(B)) +#if 1 +#include +#define __assert(COND) do { assert(COND); } while (0) +#else +#define __assert(COND) do { (void)(COND); } while (0) +#endif + +#define fgets(S, SIZE, STREAM) do { \ + char *__s4567 = S; \ + char *__res4567 = fgets(__s4567, SIZE, STREAM); \ + __assert(__s4567 == __res4567); \ +} while (0) + +#define system(CMD) do { \ + int __res4568 = system(CMD); \ + __assert(-1 != __res4568); \ +} while (0) + int action=OPT_NONE; FILE *lib, *newlib, *rel, *adb, *libindex; char FLine[MAXLINE+1]; diff --git a/support/makebin/makebin.c b/support/makebin/makebin.c index 83d4ec69..b6acaf4c 100644 --- a/support/makebin/makebin.c +++ b/support/makebin/makebin.c @@ -1,5 +1,6 @@ /** @name makebin - turn a .ihx file into a binary image. */ +#include #include #include #include @@ -48,6 +49,7 @@ int main(int argc, char **argv) { int size = 32768, pack = 0, real_size = 0; BYTE *rom; + size_t res; char line[256]; char *p; @@ -112,10 +114,13 @@ int main(int argc, char **argv) real_size = addr; } - if (pack) - fwrite(rom, 1, real_size, stdout); - else - fwrite(rom, 1, size, stdout); + if (pack) { + res = fwrite(rom, 1, real_size, stdout); + assert(res == real_size); + } else { + res = fwrite(rom, 1, size, stdout); + assert(res == size); + } return 0; } -- 2.30.2