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,40 +421,46 @@ 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;
while (*p)
if (p)
{
qse_wchar_t* eq;
eq = qse_wcsbeg (*p, name);
if (eq && *eq == QSE_WT('='))
while (*p)
{
*free = 0;
return eq + 1;
qse_wchar_t* eq;
eq = qse_wcsbeg (*p, name);
if (eq && *eq == QSE_WT('='))
{
*free = 0;
return eq + 1;
}
p++;
}
p++;
}
*/
extern char** environ;
qse_mchar_t** p = environ;
while (*p)
if (p)
{
qse_wchar_t* dup;
qse_wchar_t* eq;
dup = qse_mbstowcsdup (*p, env->mmgr); /* TODO: ignroe mbwcerr */
if (dup == QSE_NULL) return QSE_NULL;
eq = qse_wcsbeg (dup, name);
if (eq && *eq == QSE_WT('='))
while (*p)
{
*free = 1;
return eq + 1;
qse_wchar_t* dup;
qse_wchar_t* eq;
dup = qse_mbstowcsdup (*p, env->mmgr); /* TODO: ignroe mbwcerr */
if (dup == QSE_NULL) return QSE_NULL;
eq = qse_wcsbeg (dup, name);
if (eq && *eq == QSE_WT('='))
{
*free = 1;
return eq + 1;
}
QSE_MMGR_FREE (env->mmgr, dup);
p++;
}
QSE_MMGR_FREE (env->mmgr, dup);
p++;
}
return 0;
@ -467,16 +473,19 @@ 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;
while (*p)
if (p)
{
qse_mchar_t* eq;
eq = qse_mbsbeg (*p, name);
if (eq && *eq == QSE_MT('='))
while (*p)
{
*free = 0;
return eq + 1;
qse_mchar_t* eq;
eq = qse_mbsbeg (*p, name);
if (eq && *eq == QSE_MT('='))
{
*free = 0;
return eq + 1;
}
p++;
}
p++;
}
return 0;
@ -590,28 +599,34 @@ done:
extern qse_wchar_t** _wenviron;
qse_wchar_t** p = _wenviron;
while (*p)
if (p)
{
if (add_envstrw (env, *p) <= -1) return -1;
p++;
while (*p)
{
if (add_envstrw (env, *p) <= -1) return -1;
p++;
}
}
*/
extern char** environ;
qse_mchar_t** p = environ;
while (*p)
if (p)
{
qse_wchar_t* dup;
int n;
while (*p)
{
qse_wchar_t* dup;
int n;
dup = qse_mbstowcsdup (*p, env->mmgr); /* TODO: ignroe mbwcerr */
if (dup == QSE_NULL) return -1;
n = add_envstrw (env, dup);
QSE_MMGR_FREE (env->mmgr, dup);
if (n <= -1) return -1;
dup = qse_mbstowcsdup (*p, env->mmgr); /* TODO: ignroe mbwcerr */
if (dup == QSE_NULL) return -1;
n = add_envstrw (env, dup);
QSE_MMGR_FREE (env->mmgr, dup);
if (n <= -1) return -1;
p++;
p++;
}
}
@ -621,10 +636,13 @@ done:
extern char** environ;
qse_mchar_t** p = environ;
while (*p)
if (p)
{
if (add_envstrm (env, *p) <= -1) return -1;
p++;
while (*p)
{
if (add_envstrm (env, *p) <= -1) return -1;
p++;
}
}
return 0;

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);