Skip to content

MSVC and "_DEBUG" mode #1359

@gvanem

Description

@gvanem

When compiling with mongoose.c in a MSVC program in _DEBUG-mode
(with -MDd or -MTd), the strdup() is normally defined to _strdup_dbg() in
Microsoft's crtdbg.h:

   #if defined(_CRT_INTERNAL_NONSTDC_NAMES) && _CRT_INTERNAL_NONSTDC_NAMES
       #define   strdup(s)          _strdup_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
       ...

If crtdbg.h gets included after mongoose.h, it's no problem. But vice-versa could be
since src/arch_win32.h and mongoose.h redefines it to _strdup().
This will not work for a _DEBUG program (probably crash).

So I suggest this patch:

--- a/src/arch_win32.h 2021-09-13 15:24:56
+++ b/src/arch_win32.h 2021-09-24 13:27:51
@@ -51,8 +51,10 @@
 #ifndef __cplusplus
 #define snprintf _snprintf
 #define vsnprintf _vsnprintf
+#ifndef strdup
 #define strdup(x) _strdup(x)
 #endif
+#endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions