enhanced env not to crash if environ is pointing to null

This commit is contained in:
hyung-hwan 2012-12-18 15:12:53 +00:00
parent 1595a9a4f3
commit 092a8106b2
5 changed files with 78 additions and 54 deletions

View File

@ -25,11 +25,11 @@
#include <qse/cmn/chr.h>
#include <qse/cmn/opt.h>
#include <qse/cmn/path.h>
#include <qse/cmn/stdio.h>
#include <qse/cmn/main.h>
#include <qse/cmn/mbwc.h>
#include <qse/cmn/xma.h>
#include <qse/cmn/glob.h>
#include <qse/cmn/stdio.h>
#include <string.h>
#include <signal.h>

View File

@ -509,9 +509,11 @@ typedef int qse_mcint_t;
* The qse_wcint_t type defines a type that can hold a qse_wchar_t value and
* #QSE_WCHAR_EOF.
*/
#if defined(__cplusplus) && \
(!(defined(_MSC_VER) || defined(_SCO_DS)) || \
(defined(_MSC_VER) && defined(_NATIVE_WCHAR_T_DEFINED)))
#if defined(__cplusplus) && !( \
(defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)) || \
(defined(__WATCOMC__) && (__WATCOMC__ < 1200)) || \
defined(_SCO_DS) \
)
/* C++ */
typedef wchar_t qse_wchar_t;

View File

@ -421,6 +421,8 @@ static qse_wchar_t* get_env (qse_env_t* env, const qse_wchar_t* name, int* free)
extern qse_wchar_t** _wenviron;
qse_wchar_t** p = _wenviron;
if (p)
{
while (*p)
{
qse_wchar_t* eq;
@ -432,11 +434,14 @@ static qse_wchar_t* get_env (qse_env_t* env, const qse_wchar_t* name, int* free)
}
p++;
}
}
*/
extern char** environ;
qse_mchar_t** p = environ;
if (p)
{
while (*p)
{
qse_wchar_t* dup;
@ -456,6 +461,7 @@ static qse_wchar_t* get_env (qse_env_t* env, const qse_wchar_t* name, int* free)
p++;
}
}
return 0;
}
@ -467,6 +473,8 @@ static qse_mchar_t* get_env (qse_env_t* env, const qse_mchar_t* name, int* free)
extern char** environ;
qse_mchar_t** p = environ;
if (p)
{
while (*p)
{
qse_mchar_t* eq;
@ -478,6 +486,7 @@ static qse_mchar_t* get_env (qse_env_t* env, const qse_mchar_t* name, int* free)
}
p++;
}
}
return 0;
}
@ -590,16 +599,21 @@ done:
extern qse_wchar_t** _wenviron;
qse_wchar_t** p = _wenviron;
if (p)
{
while (*p)
{
if (add_envstrw (env, *p) <= -1) return -1;
p++;
}
}
*/
extern char** environ;
qse_mchar_t** p = environ;
if (p)
{
while (*p)
{
qse_wchar_t* dup;
@ -613,6 +627,7 @@ done:
p++;
}
}
return 0;
@ -621,11 +636,14 @@ done:
extern char** environ;
qse_mchar_t** p = environ;
if (p)
{
while (*p)
{
if (add_envstrm (env, *p) <= -1) return -1;
p++;
}
}
return 0;
#endif

View File

@ -949,17 +949,19 @@ create_process:
(flags & QSE_PIO_ERRTONUL))
{
ULONG action_taken;
/*
LONGLONG zero;
zero.ulLo = 0;
zero.ulHi = 0;
*/
/* TODO: selective between DosOpenL and DosOpen */
rc = DosOpenL (
rc = DosOpen /*DosOpenL*/ (
QSE_MT("NUL"),
&os2devnul,
&action_taken,
zero,
0, /*zero,*/
FILE_NORMAL,
OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE,

View File

@ -36,7 +36,9 @@ static qse_char_t* __adjust_format (const qse_char_t* format);
int qse_vfprintf (QSE_FILE *stream, const qse_char_t* fmt, va_list ap)
{
int n;
qse_char_t* nf = __adjust_format (fmt);
qse_char_t* nf;
nf = __adjust_format (fmt);
if (nf == NULL) return -1;
#if defined(QSE_CHAR_IS_MCHAR)
@ -70,7 +72,7 @@ int qse_printf (const qse_char_t* fmt, ...)
va_list ap;
va_start (ap, fmt);
n = qse_vprintf (fmt, ap);
n = qse_vfprintf (QSE_STDOUT, fmt, ap);
va_end (ap);
return n;
}
@ -82,13 +84,13 @@ int qse_vsprintf (qse_char_t* buf, qse_size_t size, const qse_char_t* fmt, va_li
if (nf == NULL) return -1;
#if defined(QSE_CHAR_IS_MCHAR)
#if defined(_WIN32) && !defined(__WATCOMC__)
#if defined(_MSC_VER) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
n = _vsnprintf (buf, size, nf, ap);
#else
n = vsnprintf (buf, size, nf, ap);
#endif
#else
#if defined(_WIN32) && !defined(__WATCOMC__)
#if defined(_MSC_VER) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
n = _vsnwprintf (buf, size, nf, ap);
#else
n = vswprintf (buf, size, nf, ap);