Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. i have a quesstion about gcc warning

i have a quesstion about gcc warning

Scheduled Pinned Locked Moved ATL / WTL / STL
help
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lxlenovostar
    wrote on last edited by
    #1

    when i complier these codes, the warning will come :

    static void err_doit(int errnoflag, int level, const char* fmt, va_list ap)
    {
    int errno_save, n;
    char buf[MAXLINE+1];

        errno\_save = errno;     //value caller might want printed
    
        #ifdef  HAVE\_VSNPRINTF
                vsnprintf(buf, MAXLINE, fmt, ap);       //this is safe
        #else
                vsprintf(buf, fmt, ap);         //this is not safe
        #endif
    
        n = strlen(buf);
        if(errnoflag)
                snprintf((char\*)(buf+n), MAXLINE-n, ";%s", strerror(errno\_save));
        strcat(buf, "\\n");
        //const char\* temp = buf;
        if(daemon\_proc)
        {
                syslog(level, (const char\*)buf);                //98
                //syslog(level, temp);
        }
        else
        {
                fflush(stdout);         //in case stdout and stderr are the same
                fputs(buf, stderr);
                fflush(stderr);
        }
    
        return;
    

    }
    </pre>

    the warnning is:
    In file included from str_cli.c:2,
    from tcpcli01.c:2:
    error.c: In function ‘void err_doit(int, int, const char*, char*)’:
    error.c:98: warning: format not a string literal and no format arguments

    i this warning, for i don't make buf to (const char*), but i try, it don't work.
    please give me some advices, thank you

    L 1 Reply Last reply
    0
    • L lxlenovostar

      when i complier these codes, the warning will come :

      static void err_doit(int errnoflag, int level, const char* fmt, va_list ap)
      {
      int errno_save, n;
      char buf[MAXLINE+1];

          errno\_save = errno;     //value caller might want printed
      
          #ifdef  HAVE\_VSNPRINTF
                  vsnprintf(buf, MAXLINE, fmt, ap);       //this is safe
          #else
                  vsprintf(buf, fmt, ap);         //this is not safe
          #endif
      
          n = strlen(buf);
          if(errnoflag)
                  snprintf((char\*)(buf+n), MAXLINE-n, ";%s", strerror(errno\_save));
          strcat(buf, "\\n");
          //const char\* temp = buf;
          if(daemon\_proc)
          {
                  syslog(level, (const char\*)buf);                //98
                  //syslog(level, temp);
          }
          else
          {
                  fflush(stdout);         //in case stdout and stderr are the same
                  fputs(buf, stderr);
                  fflush(stderr);
          }
      
          return;
      

      }
      </pre>

      the warnning is:
      In file included from str_cli.c:2,
      from tcpcli01.c:2:
      error.c: In function ‘void err_doit(int, int, const char*, char*)’:
      error.c:98: warning: format not a string literal and no format arguments

      i this warning, for i don't make buf to (const char*), but i try, it don't work.
      please give me some advices, thank you

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The specification for syslog() is

      void syslog(int priority, const char *format, ...);

      and your call uses buf as the format parameter, but its content does not contain any format control characters, and your call does not include any parameters. If you rewrite it as

      syslog(level, "%s", buf);

      it should work OK.

      Just say 'NO' to evaluated arguments for diadic functions! Ash

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups