← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] correct some snprintf usage

 

On 22 February 2015 at 03:00, Mark Roszko <mark.roszko@xxxxxxxxx> wrote:
> Fixes some cases where n-1 bytes was used as a size but snprintf
> protects against that internally. Also some hardcoded constant sizes
> changed to sizeof()

> And made a case where sprintf was used into snprintf as the path input
> as aUserPluginsPath could in theory be very stupid long if someone has
> a very stupid filesystem. Would be best if there was error handling if
> it exceeds ( snprintf will return greater than sizeof(buf) ) but I
> have no clue how that section needs cleanup.

The MinGW compiler uses the Microsoft system version of snprintf which
is not C99 compliant. I've attached a fix so that we can use snprintf
as per the C99 spec as per your patch.

I can't commit it until I can do a test compile to check everything
works okay with it. I'll have to wait until I'm home tonight. The
proper use of snprintf is much more sane!

The MS version is a real pain, it returns -1 if the contents do not
fit in the buffer and more importantly it does NOT guarantee to NULL
terminate even if it returns a positive result!!

Best Regards,

Brian.
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt	2015-02-20 13:46:12 +0000
+++ CMakeLists.txt	2015-02-23 11:04:26 +0000
@@ -223,6 +223,10 @@
             endif()
         endif()
 
+        # The MinGW compiler can use the microsoft system snprintf as standard and it has a broken
+        # API with respect to the C99 standard, so make sure we force it to use its own compliant
+        # snprintf
+        add_definitions(-D__USE_MINGW_ANSI_STDIO=1)
     else()
         # We build DLL/DSOs from static libraries, so create position independent
         # code for all cases, since we do not have DLL/DSO specific static


Follow ups

References