Skip to content

Commit ce0669c

Browse files
committed
Merge branch 'PHP-7.1'
* PHP-7.1: add folds fix possible null dereference
2 parents 5e6faf2 + 6ffa1d2 commit ce0669c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

win32/codepage.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ PW32CP wchar_t *php_win32_cp_env_any_to_w(const char* env)
394394
}/*}}}*/
395395

396396
static BOOL php_win32_cp_cli_io_setup(void)
397-
{
397+
{/*{{{*/
398398
BOOL ret = TRUE;
399399

400400
if (PG(input_encoding) && PG(input_encoding)[0]) {
@@ -420,7 +420,7 @@ static BOOL php_win32_cp_cli_io_setup(void)
420420
}
421421

422422
return ret;
423-
}
423+
}/*}}}*/
424424

425425
PW32CP const struct php_win32_cp *php_win32_cp_do_setup(const char *enc)
426426
{/*{{{*/
@@ -498,16 +498,18 @@ PW32CP const struct php_win32_cp *php_win32_cp_cli_do_setup(DWORD id)
498498

499499
PW32CP const struct php_win32_cp *php_win32_cp_cli_do_restore(DWORD id)
500500
{/*{{{*/
501-
if (!id && orig_cp) {
502-
id = orig_cp->id;
501+
BOOL cli_io_restored = TRUE;
502+
503+
if (orig_in_cp) {
504+
cli_io_restored = cli_io_restored && SetConsoleCP(orig_in_cp->id);
503505
}
504506

505-
if (SetConsoleCP(orig_in_cp->id) && SetConsoleOutputCP(orig_out_cp->id)) {
506-
if (orig_cp) {
507-
return orig_cp;
508-
} else {
509-
return php_win32_cp_set_by_id(id);
510-
}
507+
if (orig_out_cp) {
508+
cli_io_restored = cli_io_restored && SetConsoleOutputCP(orig_out_cp->id);
509+
}
510+
511+
if (cli_io_restored && id) {
512+
return php_win32_cp_set_by_id(id);
511513
}
512514

513515
return NULL;

0 commit comments

Comments
 (0)