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. C / C++ / MFC
  4. debugging sprintf -VS/C++

debugging sprintf -VS/C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++visual-studiosysadmintutorialquestion
3 Posts 3 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.
  • A Offline
    A Offline
    Alan Kurlansky
    wrote on last edited by
    #1

    Is there a tool available to process source code to detect mismatches between the sprintf format string and the arguments that follow? For example specifying a %s and neglecting to provide a c string to satisfy it, etc. I use hundreds of sprintf's to format log messages and am looking for a way to insure correctness without eyeballing each and everyone of them. When this happens during runtime in my code the program thread seems to hang and when it's the main server thread the other secondary threads cease to get serviced and as they are designed to timeout, they do, and a programmatic exit occurs.

    A M 2 Replies Last reply
    0
    • A Alan Kurlansky

      Is there a tool available to process source code to detect mismatches between the sprintf format string and the arguments that follow? For example specifying a %s and neglecting to provide a c string to satisfy it, etc. I use hundreds of sprintf's to format log messages and am looking for a way to insure correctness without eyeballing each and everyone of them. When this happens during runtime in my code the program thread seems to hang and when it's the main server thread the other secondary threads cease to get serviced and as they are designed to timeout, they do, and a programmatic exit occurs.

      A Offline
      A Offline
      Aescleal
      wrote on last edited by
      #2

      If you're using C++ don't fart about with sprintf, use std::stringstream - you'll avoid problems of lobbing the wrong thing at a particular format specifier. If you're stuck using C then there's not a lot I can suggest although PC-Lint is pretty good at finding errors in the printf family of functions. Cheers, Ash

      1 Reply Last reply
      0
      • A Alan Kurlansky

        Is there a tool available to process source code to detect mismatches between the sprintf format string and the arguments that follow? For example specifying a %s and neglecting to provide a c string to satisfy it, etc. I use hundreds of sprintf's to format log messages and am looking for a way to insure correctness without eyeballing each and everyone of them. When this happens during runtime in my code the program thread seems to hang and when it's the main server thread the other secondary threads cease to get serviced and as they are designed to timeout, they do, and a programmatic exit occurs.

        M Offline
        M Offline
        Moak
        wrote on last edited by
        #3

        Alan Kurlansky wrote:

        detect mismatches between the sprintf format string and the arguments that follow?

        Yes, there are a couple of tools available. Have a look at the following:

        • Splint checks for vulnerabilities and coding mistakes
        • PC-Lint the "classic" code analysis tool
        • Dr Dobbs had a full article about code analysis
        • also see Wikipedia: tools for static code_analysis for C and C++

        Happy debugging! :) M PS: This post is for developers who prefer format() over STL string streams. PPS: And if you are one of them, you could have a look at Boost Format library. :)

        Chat in Europe :java: Now with 24% more Twitter

        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