#348 Visual Studio snprintf

Kris Lamb

When wrapping a lua module with swig 3.0.0 and trying to compile under visual studio the wrapped cpp file generates an error with snprintf inside the SWIG_Lua_Class_tostring function. Previously swig used sprintf which the microsoft compiler supports. I'm not sure what the right direction to take is, I could add some #ifdef's and use an appropriate substitute like _snprintf_s


  • Kris Lamb

    Kris Lamb - 2014-03-21

    I chose to change the luarun.swg file to this at line 1002:

    #ifdef _MSC_VER
    _snprintf_s(output, 255, "<%s userdata: %lX>", className, userData);
    snprintf(output, 255, "<%s userdata: %lX>", className, userData);

    It works for me, but I haven't tried under other build environments (although I can't see anything wrong with it at the moment)

  • William Fulton

    William Fulton - 2014-03-22

    Kris, I'd like a patch that uses portable code, that is, no macros. If the original was using sprintf, then let's go back to that.

    This is a duplicate of github issue https://github.com/swig/swig/issues/152. A github patch is preferable, but not mandatory! The patches on github are automatically tested on Travis.

  • Kris Lamb

    Kris Lamb - 2014-03-24

    Since this is a duplicate we should just close this.

  • William Fulton

    William Fulton - 2014-03-25
    • status: open --> closed
    • assigned_to: William Fulton
    • Group: -->

Log in to post a comment.