fix gcc 4.x warnings trunk
authornathan
Mon, 17 Aug 2009 20:56:48 +0800
branchtrunk
changeset 29640ce9201139
parent 28 38d35ff3d93f
child 30 f8a59739816b
fix gcc 4.x warnings
data-mp3.c
data.c
data.h
decoder-snd.c
decoder.c
menu.c
mp3.c
mplayer.c
network.c
player-mp3.c
player-mplayer.c
stream.c
     1.1 --- a/data-mp3.c	Mon Aug 17 20:55:55 2009 +0800
     1.2 +++ b/data-mp3.c	Mon Aug 17 20:56:48 2009 +0800
     1.3 @@ -93,11 +93,11 @@
     1.4  
     1.5  void cImageConvert::Action(void)
     1.6  {
     1.7 -  nice(3);
     1.8 -  char *m, *cmd, *qp, *qm;
     1.9 -  asprintf(&m,"%s%s.mpg",imagecache,image);
    1.10 +  if(nice(3)<0);
    1.11 +  char *qp, *qm;
    1.12 +  char *m=aprintf("%s%s.mpg",imagecache,image);
    1.13    di(printf("image: convert started %s -> %s\n",image,m))
    1.14 -  asprintf(&cmd,"%s \"%s\" \"%s\"",imageconv,qp=Quote(image),qm=Quote(m));
    1.15 +  char *cmd=aprintf("%s \"%s\" \"%s\"",imageconv,qp=Quote(image),qm=Quote(m));
    1.16    int r=system(cmd);
    1.17    if(r!=0) di(printf("image: convert returned with code %d. Failed?\n",r))
    1.18    free(cmd); free(qp); free(qm); free(m);
    1.19 @@ -264,9 +264,8 @@
    1.20  
    1.21  const char *cSong::CheckImage(const char *base) const
    1.22  {
    1.23 -  char *p;
    1.24    int n;
    1.25 -  asprintf(&p,"%s/%s.%n     ",obj->Source()->BaseDir(),base,&n);
    1.26 +  char *p=aprintf("%s/%s.%n     ",obj->Source()->BaseDir(),base,&n);
    1.27    for(const char **s=img_suff; *s; s++) {
    1.28  #ifdef DEBUG
    1.29      if(strlen(*s)>5) printf("ERROR: buffer overflow in CheckImage ext=%s\n",*s);
    1.30 @@ -300,8 +299,7 @@
    1.31    int res=0;
    1.32    if(image || FindImage()) {
    1.33      di(printf("image: loading image %s\n",image))
    1.34 -    char *m;
    1.35 -    asprintf(&m,"%s%s.mpg",imagecache,image);
    1.36 +    char *m=aprintf("%s%s.mpg",imagecache,image);
    1.37      if(access(m,R_OK)) {
    1.38        di(printf("image: not cached\n"))
    1.39        if(queueStat<0) {
    1.40 @@ -497,8 +495,8 @@
    1.41  
    1.42  const char *cPlayList::AddExt(const char *FileName, const char *Ext)
    1.43  {
    1.44 -  free(extbuffer); extbuffer=0;
    1.45 -  asprintf(&extbuffer,"%s%s",FileName,Ext);
    1.46 +  free(extbuffer);
    1.47 +  extbuffer=aprintf("%s%s",FileName,Ext);
    1.48    return extbuffer;
    1.49  }
    1.50  
     2.1 --- a/data.c	Mon Aug 17 20:55:55 2009 +0800
     2.2 +++ b/data.c	Mon Aug 17 20:56:48 2009 +0800
     2.3 @@ -23,6 +23,7 @@
     2.4  #include <dirent.h>
     2.5  #include <stdlib.h>
     2.6  #include <stdio.h>
     2.7 +#include <stdarg.h>
     2.8  #include <errno.h>
     2.9  #include <sys/stat.h>
    2.10  #include <sys/types.h>
    2.11 @@ -60,8 +61,7 @@
    2.12  
    2.13  char *AddPath(const char *dir, const char *filename)
    2.14  {
    2.15 -  char *name=0;
    2.16 -  asprintf(&name,"%s/%s",dir,filename);
    2.17 +  char *name=aprintf("%s/%s",dir,filename);
    2.18    return name;
    2.19  }
    2.20  
    2.21 @@ -84,13 +84,23 @@
    2.22    return true;
    2.23  }
    2.24  
    2.25 +char *aprintf(const char *fmt, ...)
    2.26 +{
    2.27 +  va_list ap;
    2.28 +  va_start(ap,fmt);
    2.29 +  char *str=0;
    2.30 +  if(vasprintf(&str,fmt,ap)<0);
    2.31 +  va_end(ap);
    2.32 +  return str;
    2.33 +}
    2.34 +
    2.35  // -- cScanDir --------------------------------------------------------------
    2.36  
    2.37  bool cScanDir::ScanDir(cFileSource *src, const char *subdir, eScanType type, const char * const *spec, const char * const *excl, bool recursiv)
    2.38  {
    2.39    bool res=true;
    2.40 -  char *dir, *f=0;
    2.41 -  asprintf(&dir,subdir ? "%s/%s":"%s",src->BaseDir(),subdir);
    2.42 +  char *f=0;
    2.43 +  char *dir=aprintf(subdir ? "%s/%s":"%s",src->BaseDir(),subdir);
    2.44    DIR *d=opendir(dir);
    2.45    if(d) {
    2.46      struct dirent64 *e;
    2.47 @@ -113,8 +123,7 @@
    2.48          }
    2.49        if(S_ISDIR(st.st_mode)) {
    2.50          if(type==stFile && recursiv) {
    2.51 -          char *s;
    2.52 -          asprintf(&s,subdir ? "%2$s/%1$s":"%s",e->d_name,subdir);
    2.53 +          char *s=aprintf(subdir ? "%2$s/%1$s":"%s",e->d_name,subdir);
    2.54            res=ScanDir(src,s,type,spec,excl,recursiv);
    2.55            free(s);
    2.56            if(!res) break;
    2.57 @@ -256,15 +265,15 @@
    2.58  
    2.59  void cFileObj::Set(void)
    2.60  {
    2.61 -  free(path); path=0;
    2.62 -  asprintf(&path,subdir ? "%2$s/%1$s":"%s",name,subdir);
    2.63 +  free(path);
    2.64 +  path=aprintf(subdir ? "%2$s/%1$s":"%s",name,subdir);
    2.65    free(fpath); fpath=0;
    2.66    MakeFullName(&fpath,name);
    2.67  }
    2.68  
    2.69  void cFileObj::MakeFullName(char **fp, const char *Name)
    2.70  {
    2.71 -  asprintf(fp,subdir ? "%1$s/%3$s/%2$s":"%s/%s",source->BaseDir(),Name,subdir);
    2.72 +  *fp=aprintf(subdir ? "%1$s/%3$s/%2$s":"%s/%s",source->BaseDir(),Name,subdir);
    2.73  }
    2.74  
    2.75  bool cFileObj::GuessType(void)
    2.76 @@ -498,8 +507,7 @@
    2.77  {
    2.78    static const char *str[] = { "mount","unmount","eject","status" };
    2.79    
    2.80 -  char *cmd=0;
    2.81 -  asprintf(&cmd,"%s %s %s",mountscript,str[act],basedir);
    2.82 +  char *cmd=aprintf("%s %s %s",mountscript,str[act],basedir);
    2.83    bool res=(system(cmd)==0);
    2.84    free(cmd);
    2.85    return res;
     3.1 --- a/data.h	Mon Aug 17 20:55:55 2009 +0800
     3.2 +++ b/data.h	Mon Aug 17 20:56:48 2009 +0800
     3.3 @@ -31,6 +31,7 @@
     3.4  extern char *Quote(const char *str);
     3.5  extern char *AddPath(const char *dir, const char *filename);
     3.6  extern bool CheckVDRVersion(int Version, int Major, int Minor, const char *text=0);
     3.7 +extern char *aprintf(const char *fmt, ...) __attribute__ ((format (printf,1,2)));
     3.8  
     3.9  // ----------------------------------------------------------------
    3.10  
     4.1 --- a/decoder-snd.c	Mon Aug 17 20:55:55 2009 +0800
     4.2 +++ b/decoder-snd.c	Mon Aug 17 20:56:48 2009 +0800
     4.3 @@ -732,8 +732,7 @@
     4.4                char *s=index(cat,' '); if(s) *s=0;
     4.5                code=DoCddbCmd("cddb read %s %08x\n",cat,id->discid);
     4.6                if(code==210) {
     4.7 -                char *name=0;
     4.8 -                asprintf(&name,"%s/%s/%08x",cddbpath,cat,id->discid);
     4.9 +                char *name=aprintf("%s/%s/%08x",cddbpath,cat,id->discid);
    4.10                  if(MakeDirs(name,false)) {
    4.11                    FILE *out=fopen(name,"w");
    4.12                    if(out) {
    4.13 @@ -790,7 +789,7 @@
    4.14    va_list ap;
    4.15    va_start(ap,format);
    4.16    char *buff=0;
    4.17 -  vasprintf(&buff,format,ap);
    4.18 +  if(vasprintf(&buff,format,ap)<0);
    4.19    va_end(ap);
    4.20  #ifdef CDDB_DEBUG
    4.21    printf("cddb: -> %s",buff);
     5.1 --- a/decoder.c	Mon Aug 17 20:55:55 2009 +0800
     5.2 +++ b/decoder.c	Mon Aug 17 20:56:48 2009 +0800
     5.3 @@ -220,7 +220,7 @@
     5.4          FsType=0;
     5.5          struct statfs64 sfs;
     5.6          if(!statfs64(Filename,&sfs)) {
     5.7 -          if(Removable()) asprintf(&FsID,"%llx:%llx",sfs.f_blocks,sfs.f_files);
     5.8 +          if(Removable()) FsID=aprintf("%llx:%llx",sfs.f_blocks,sfs.f_files);
     5.9            FsType=sfs.f_type;
    5.10            }
    5.11          else if(errno!=ENOSYS && log) { esyslog("ERROR: can't statfs %s: %s",Filename,strerror(errno)); }
    5.12 @@ -602,7 +602,7 @@
    5.13  void cInfoCache::Action(void)
    5.14  {
    5.15    d(printf("cache: id3 cache purge thread started (pid=%d)\n",getpid()))
    5.16 -  nice(3);
    5.17 +  if(nice(3)<0);
    5.18    lock.Lock();
    5.19    for(int i=0,n=0 ; i<CACHELINES && Running(); i++) {
    5.20      cCacheData *dat=FirstEntry(i);
     6.1 --- a/menu.c	Mon Aug 17 20:55:55 2009 +0800
     6.2 +++ b/menu.c	Mon Aug 17 20:56:48 2009 +0800
     6.3 @@ -71,8 +71,7 @@
     6.4  
     6.5  void cMenuBrowseItem::Set(void)
     6.6  {
     6.7 -  char *buffer=0;
     6.8 -  asprintf(&buffer,item->Type()==otFile?"%s":"[%s]",item->Name());
     6.9 +  char *buffer=aprintf(item->Type()==otFile?"%s":"[%s]",item->Name());
    6.10    SetText(buffer,false);
    6.11  }
    6.12  
    6.13 @@ -251,8 +250,7 @@
    6.14  
    6.15  void cMenuSourceItem::Set(void)
    6.16  {
    6.17 -  char *buffer=0;
    6.18 -  asprintf(&buffer, "%s\t%s\t%s", source->NeedsMount()?(source->Status()?"*":">"):"", source->Description(), source->BaseDir());
    6.19 +  char *buffer=aprintf("%s\t%s\t%s", source->NeedsMount()?(source->Status()?"*":">"):"", source->Description(), source->BaseDir());
    6.20    SetText(buffer,false);
    6.21  }
    6.22  
     7.1 --- a/mp3.c	Mon Aug 17 20:55:55 2009 +0800
     7.2 +++ b/mp3.c	Mon Aug 17 20:56:48 2009 +0800
     7.3 @@ -803,8 +803,7 @@
     7.4    if(si) {
     7.5      Item(tr("Filename"),name);
     7.6      if(si->HasInfo() && si->Total>0) {
     7.7 -      char *buf=0;
     7.8 -      asprintf(&buf,"%02d:%02d",si->Total/60,si->Total%60);
     7.9 +      char *buf=aprintf("%02d:%02d",si->Total/60,si->Total%60);
    7.10        Item(tr("Length"),buf);
    7.11        free(buf);
    7.12        Item(tr("Title"),si->Title);
    7.13 @@ -823,8 +822,7 @@
    7.14  {
    7.15    cOsdItem *item;
    7.16    if(num>=0.0) {
    7.17 -    char *buf=0;
    7.18 -    asprintf(&buf,format?format:"%.f",num);
    7.19 +    char *buf=aprintf(format?format:"%.f",num);
    7.20      item=Item(name,buf);
    7.21      free(buf);
    7.22      }
    7.23 @@ -834,8 +832,7 @@
    7.24  
    7.25  cOsdItem *cMenuID3Info::Item(const char *name, const char *text)
    7.26  {
    7.27 -  char *buf=0;
    7.28 -  asprintf(&buf,"%s:\t%s",name,text?text:"");
    7.29 +  char *buf=aprintf("%s:\t%s",name,text?text:"");
    7.30    cOsdItem *item = new cOsdItem(buf,osBack);
    7.31    item->SetSelectable(false);
    7.32    free(buf);
    7.33 @@ -939,13 +936,13 @@
    7.34  
    7.35  void cMenuPlayListItem::Set(void)
    7.36  {
    7.37 -  char *buffer=0;
    7.38 +  char *buffer;
    7.39    cSongInfo *si=song->Info(false);
    7.40    if(showID3 && !si) si=song->Info();
    7.41    if(showID3 && si && si->Title)
    7.42 -    asprintf(&buffer, "%d.\t%s",song->Index()+1,*TitleArtist(si->Title,si->Artist));
    7.43 +    buffer=aprintf("%d.\t%s",song->Index()+1,*TitleArtist(si->Title,si->Artist));
    7.44    else
    7.45 -    asprintf(&buffer, "%d.\t<%s>",song->Index()+1,song->Name());
    7.46 +    buffer=aprintf("%d.\t<%s>",song->Index()+1,song->Name());
    7.47    SetText(buffer,false);
    7.48  }
    7.49  
    7.50 @@ -1109,8 +1106,7 @@
    7.51    free(newname); newname=0;
    7.52  
    7.53    oldname=Oldname;
    7.54 -  char *buf=NULL;
    7.55 -  asprintf(&buf,"%s\t%s",tr("Old name:"),oldname);
    7.56 +  char *buf=aprintf("%s\t%s",tr("Old name:"),oldname);
    7.57    cOsdItem *old = new cOsdItem(buf,osContinue);
    7.58    old->SetSelectable(false);
    7.59    Add(old);
    7.60 @@ -1157,8 +1153,7 @@
    7.61  
    7.62  void cMenuMP3Item::Set(void)
    7.63  {
    7.64 -  char *buffer=0;
    7.65 -  asprintf(&buffer," %s",playlist->BaseName());
    7.66 +  char *buffer=aprintf(" %s",playlist->BaseName());
    7.67    SetText(buffer,false);
    7.68  }
    7.69  
    7.70 @@ -1440,7 +1435,7 @@
    7.71    static char *help_str=0;
    7.72    
    7.73    free(help_str);    //                                     for easier orientation, this is column 80|
    7.74 -  asprintf(&help_str,"  -m CMD,   --mount=CMD    use CMD to mount/unmount/eject mp3 sources\n"
    7.75 +  help_str=aprintf(  "  -m CMD,   --mount=CMD    use CMD to mount/unmount/eject mp3 sources\n"
    7.76                       "                           (default: %s)\n"
    7.77                       "  -n CMD,   --network=CMD  execute CMD before & after network access\n"
    7.78                       "                           (default: %s)\n"
     8.1 --- a/mplayer.c	Mon Aug 17 20:55:55 2009 +0800
     8.2 +++ b/mplayer.c	Mon Aug 17 20:56:48 2009 +0800
     8.3 @@ -615,7 +615,7 @@
     8.4    static char *help_str=0;
     8.5    
     8.6    free(help_str);    //                                     for easier orientation, this is column 80|
     8.7 -  asprintf(&help_str,"  -m CMD,   --mount=CMD    use CMD to mount/unmount/eject mp3 sources\n"
     8.8 +  help_str=aprintf(  "  -m CMD,   --mount=CMD    use CMD to mount/unmount/eject mp3 sources\n"
     8.9                       "                           (default: %s)\n"
    8.10                       "  -M CMD,   --mplayer=CMD  use CMD when calling MPlayer\n"
    8.11                       "                           (default: %s)\n"
     9.1 --- a/network.c	Mon Aug 17 20:55:55 2009 +0800
     9.2 +++ b/network.c	Mon Aug 17 20:56:48 2009 +0800
     9.3 @@ -38,6 +38,7 @@
     9.4  #include "common.h"
     9.5  #include "setup-mp3.h"
     9.6  #include "network.h"
     9.7 +#include "data.h"
     9.8  
     9.9  #define CON_TIMEOUT      30*1000   // default timeout (ms) for connect operation
    9.10  #define RW_TIMEOUT       30*1000   // default timeout (ms) for read/write operations
    9.11 @@ -53,10 +54,9 @@
    9.12  {
    9.13    int res=-1;
    9.14    if(cmd) {
    9.15 -    char *tmp=0;
    9.16 -    if(Name)
    9.17 -      asprintf(&tmp,"%s %s \"%s\"",cmd,State,*strescape(Name,"\"$"));
    9.18 -    else asprintf(&tmp,"%s %s",cmd,State);
    9.19 +    char *tmp;
    9.20 +    if(Name) tmp=aprintf("%s %s \"%s\"",cmd,State,*strescape(Name,"\"$"));
    9.21 +    else     tmp=aprintf("%s %s",cmd,State);
    9.22  
    9.23      d(printf("run: executing '%s'\n",tmp))
    9.24      res=SystemExec(tmp);
    10.1 --- a/player-mp3.c	Mon Aug 17 20:55:55 2009 +0800
    10.2 +++ b/player-mp3.c	Mon Aug 17 20:56:48 2009 +0800
    10.3 @@ -822,7 +822,7 @@
    10.4  void cPlayManager::Action(void)
    10.5  {
    10.6    db(printf("mgr: background scan thread started (pid=%d)\n", getpid()))
    10.7 -  nice(5);
    10.8 +  if(nice(5)<0);
    10.9    listMutex.Lock();
   10.10    while(!stopscan) {
   10.11      for(scan=list.First(); !stopscan && !release && scan; scan=list.Next(scan)) {
   10.12 @@ -1429,7 +1429,7 @@
   10.13          int real=sr;
   10.14          CHECK(ioctl(fd,SNDCTL_DSP_SPEED,&real));
   10.15          d(printf("oss: DSP samplerate now %d\n",real))
   10.16 -        if(abs(real-sr)<sr/50) {
   10.17 +        if((unsigned int)abs(real-sr)<sr/50) {
   10.18            outSr=sr;
   10.19            d(printf("mp3-oss: DSP reset done\n"))
   10.20            return true;
    11.1 --- a/player-mplayer.c	Mon Aug 17 20:55:55 2009 +0800
    11.2 +++ b/player-mplayer.c	Mon Aug 17 20:56:48 2009 +0800
    11.3 @@ -181,8 +181,7 @@
    11.4      modified=global=false;
    11.5      free(resfile); resfile=0;
    11.6      delete resobj; resobj=new cFileObj(file);
    11.7 -    char *s;
    11.8 -    asprintf(&s,file->Subdir() ? "%s/%s":"%s",file->Source()->BaseDir(),file->Subdir());
    11.9 +    char *s=aprintf(file->Subdir() ? "%s/%s":"%s",file->Source()->BaseDir(),file->Subdir());
   11.10      if(MPlayerSetup.ResumeMode==1 || 
   11.11         (access(s,W_OK) && (errno==EACCES || errno==EROFS))) {
   11.12        global=true;
   11.13 @@ -581,7 +580,7 @@
   11.14      va_list ap;
   11.15      va_start(ap,format);
   11.16      char *buff=0;
   11.17 -    vasprintf(&buff,format,ap);
   11.18 +    if(vasprintf(&buff,format,ap)<0);
   11.19      Lock();
   11.20      // check for writeable pipe i.e. prevent broken pipe signal
   11.21      if(!brokenPipe) {
    12.1 --- a/stream.c	Mon Aug 17 20:55:55 2009 +0800
    12.2 +++ b/stream.c	Mon Aug 17 20:56:48 2009 +0800
    12.3 @@ -28,6 +28,7 @@
    12.4  #include "setup-mp3.h"
    12.5  #include "stream.h"
    12.6  #include "network.h"
    12.7 +#include "data.h"
    12.8  #include "menu-async.h"
    12.9  #include "i18n.h"
   12.10  #include "version.h"
   12.11 @@ -366,10 +367,10 @@
   12.12    bool res=false;
   12.13    char buff[2048];
   12.14  
   12.15 -  char *h, *p;
   12.16 -  asprintf(&h,port!=DEFAULT_PORT ? "%s:%d":"%s",host,port);
   12.17 -  if(MP3Setup.UseProxy) asprintf(&p,"http://%s%s",h,path);
   12.18 -  else asprintf(&p,"%s",path);
   12.19 +  char *p;
   12.20 +  char *h=aprintf(port!=DEFAULT_PORT ? "%s:%d":"%s",host,port);
   12.21 +  if(MP3Setup.UseProxy) p=aprintf("http://%s%s",h,path);
   12.22 +  else p=aprintf("%s",path);
   12.23  
   12.24    char a[1024];
   12.25    a[0]=0;