From bf29a15242427fde898cb3f9bd260aedca87bf3f Mon Sep 17 00:00:00 2001 From: kbinny62 Date: Fri, 23 Jun 2017 18:15:25 +0000 Subject: [PATCH 1/2] xmltest: create dir resources/out to avoid crashes Since many of the tests reopen files generated under resources/out to reuse as input without performing error checking, explicity create directory to mitigate segfaults. --- xmltest.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/xmltest.cpp b/xmltest.cpp index 91a5626..336aeef 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -5,16 +5,20 @@ #endif #include "tinyxml2.h" +#include #include #include #include -#if defined( _MSC_VER ) +#if defined( _MSC_VER ) || defined (WIN32) #include #define WIN32_LEAN_AND_MEAN #include _CrtMemState startMemState; _CrtMemState endMemState; +#else + #include + #include #endif using namespace tinyxml2; @@ -334,6 +338,15 @@ int main( int argc, const char ** argv ) } fclose( fp ); +#if defined WIN32 + if ( !CreateDirectory( "resources/out", NULL ) && GetLastError() != ERROR_ALREADY_EXISTS ) { +#else + if ( mkdir( "resources/out", 0750 ) == -1 && errno != EEXIST ) { +#endif + printf( "Unable to create directory 'resources/out': %s\n", strerror( errno ) ); + exit( 1 ); + } + XMLTest( "Example-1", 0, example_1() ); XMLTest( "Example-2", 0, example_2() ); XMLTest( "Example-3", 0, example_3() ); From 9720fbaf479f63bc8c0f46305af931ca2c38a232 Mon Sep 17 00:00:00 2001 From: kbinny62 Date: Tue, 27 Jun 2017 01:40:33 +0000 Subject: [PATCH 2/2] xmltest.cpp: path separator is '\\' under WIN32 --- xmltest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmltest.cpp b/xmltest.cpp index 336aeef..3d4856a 100644 --- a/xmltest.cpp +++ b/xmltest.cpp @@ -339,9 +339,9 @@ int main( int argc, const char ** argv ) fclose( fp ); #if defined WIN32 - if ( !CreateDirectory( "resources/out", NULL ) && GetLastError() != ERROR_ALREADY_EXISTS ) { + if ( !CreateDirectory( "resources\\out", NULL ) && GetLastError() != ERROR_ALREADY_EXISTS ) { #else - if ( mkdir( "resources/out", 0750 ) == -1 && errno != EEXIST ) { + if ( mkdir( "resources/out", S_IRWXU | S_IRGRP | S_IXGRP ) == -1 && errno != EEXIST ) { #endif printf( "Unable to create directory 'resources/out': %s\n", strerror( errno ) ); exit( 1 );