[Pkg-mono-devel] Silent crash when calling vsprintf from C#

Pieter pieter.winter at stonethree.com
Wed Sep 23 06:27:07 UTC 2015


Hi,

I have some code that I originally wrote in VisualStudio on Windows that I
am now also running in mono in Ubuntu 14.

I use vsprintf in my code, and when I call it in mono, then my application
crashes without giving me any warning.

Below is the code in its simplest form.  Calling delme() should show out the
problem.

Does anybody know why this happens, why it crashes without any information,
and what I can do to fix it?

Thanks,

Pieter


    static void delme()
    {
      StringBuilder result = new StringBuilder(1024);
      byte[] args = new byte[4];
      args[0] = 0;
      args[1] = 0;
      args[2] = 0;
      args[3] = 0;

      vsprintf(result, "This does not do any formatting.", args); // <--
This only crashes if args is null, even though it is not used.
      vsprintf(result, "The count is %i.", args); // <-- Program crashes
when stepping over this line.
      MessageBox.Show(result.ToString());
    }

    [DllImport("libc", SetLastError = false, CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.Cdecl)]
    public static extern int vsprintf(StringBuilder buff, string format,
byte[] args);



--
View this message in context: http://mono.1490590.n4.nabble.com/Silent-crash-when-calling-vsprintf-from-C-tp4666642.html
Sent from the Debian Mono mailing list archive at Nabble.com.



More information about the Pkg-mono-devel mailing list