Skip to content

Commit b11c86b

Browse files
committed
PCE: Fixed possible issues when loading state
A mismatch might happen in the future if we resize an integer or increase the system memory. Now we check that block.len is what we expect. - If it is smaller than expected, we pad the rest with zeroes (little endian casting). - If it is bigger, we crop it.
1 parent c80773e commit b11c86b

File tree

3 files changed

+7
-28
lines changed

3 files changed

+7
-28
lines changed

base.cmake

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@ include($ENV{IDF_PATH}/tools/cmake/project.cmake)
22
set(EXTRA_COMPONENT_DIRS "${CMAKE_CURRENT_LIST_DIR}/components")
33
set(SDKCONFIG_DEFAULTS "${CMAKE_CURRENT_LIST_DIR}/base.sdkconfig")
44

5-
execute_process(
6-
COMMAND git describe --tags --abbrev=5 --long --dirty=*
7-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
8-
OUTPUT_VARIABLE PROJECT_VER
9-
OUTPUT_STRIP_TRAILING_WHITESPACE
10-
)
11-
12-
if(NOT PROJECT_VER)
13-
string(TIMESTAMP TODAY "%Y.%m.%d")
14-
set(PROJECT_VER "${TODAY}-nogit")
15-
endif()
16-
175
macro(rg_setup_compile_options)
186
set(RG_TARGET "RG_TARGET_$ENV{RG_TARGET}")
197
message("Target: ${RG_TARGET}")

components/retro-go/component.mk

Lines changed: 0 additions & 12 deletions
This file was deleted.

pce-go/components/pce-go/pce-go.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
#include "pce.h"
1212

1313
/**
14-
* Describes what is saved in a save state. Changing the order will break
15-
* previous saves so add a place holder if necessary. Eventually we could use
16-
* the keys to make order irrelevant...
14+
* Save state file description.
1715
*/
1816
#define SVAR_1(k, v) { {k, 1, 1}, &v }
1917
#define SVAR_2(k, v) { {k, 2, 2}, &v }
@@ -341,11 +339,16 @@ LoadState(const char *name)
341339
{
342340
if (strncmp(var->desc.key, block.key, 12) == 0)
343341
{
344-
if (!fread(var->ptr, var->desc.len, 1, fp))
342+
size_t len = MIN((size_t)var->desc.len, (size_t)block.len);
343+
if (!fread(var->ptr, len, 1, fp))
345344
{
346345
MESSAGE_ERROR("fread error reading block data\n");
347346
goto _cleanup;
348347
}
348+
if (len < var->desc.len)
349+
{
350+
memset(var->ptr + len, 0, var->desc.len - len);
351+
}
349352
MESSAGE_INFO("Loaded %s\n", var->desc.key);
350353
break;
351354
}

0 commit comments

Comments
 (0)