Build error in Visual C++ 2008 (fix shown)

  • Salvor Hardin
    Salvor Hardin

    When JSON_UNICODE is not defined, compile fails in NumberToString.h line 97:

      snprintf(result, 63, "%f", value);

    Perhaps you can use _snprintf_s() like this to fix the compile error:

    #if _MSC_VER
      _snprintf_s(result, 63, 63, "%f", value); //yes, 63 appears twice using _snprintf_s()
      snprintf(result, 63, "%f", value);

    Visual C++'s _snprintf_s() has security enhancements, and is preferred over Visual C++'s  _snprintf(). 

    Visual C++'s _snprintf() is not 100% standards compliant like snprintf() despite having same parameters, so using _snprintf_s() will avoid confusion by having an obviously different name and parameter list.

  • Thank you for the fix, I am currently working on a new upgrade, it should be out tomorrow, this fix will be in it.  If you notice any other problems with using libjson in Visual C++, please let me know.  I don't own a Windows machine, nor do I have access to any at work, so the VC++ testing is minimal.