Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix allocations overflow crash #1100

Merged
merged 1 commit into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ out/
.vscode/
*.orig
eressea.ini
CMakeUserPresets.json
Debug
Release

Expand Down
13 changes: 13 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 2,
"configurePresets": [
{
"name": "vcpkg",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
}
]
}
34 changes: 20 additions & 14 deletions src/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,26 @@ static void parse_inifile(lua_State * L, const dictionary * d, const char *secti
const char *arg;
size_t len = strlen(section);

/* defaults */
arg = config_get("config.install");
if (arg) {
lua_pushstring(L, "install");
lua_pushstring(L, arg);
lua_rawset(L, -3);
}
lua_pushstring(L, "basepath");
lua_pushstring(L, basepath());
lua_rawset(L, -3);
lua_pushstring(L, "reportpath");
lua_pushstring(L, reportpath());
lua_rawset(L, -3);
arg = config_get("config.rules");
if (arg) {
lua_pushstring(L, "rules");
lua_pushstring(L, arg);
lua_rawset(L, -3);
}

for (i = 0; d && i != d->n; ++i) {
const char *key = d->key[i];
if (strncmp(section, key, len) == 0 && key[len] == ':') {
Expand All @@ -846,20 +866,6 @@ static void parse_inifile(lua_State * L, const dictionary * d, const char *secti
lua_rawset(L, -3);
}
}

/* special case */
lua_pushstring(L, "basepath");
lua_pushstring(L, basepath());
lua_rawset(L, -3);
lua_pushstring(L, "reportpath");
lua_pushstring(L, reportpath());
lua_rawset(L, -3);
arg = config_get("config.rules");
if (arg) {
lua_pushstring(L, "rules");
lua_pushstring(L, arg);
lua_rawset(L, -3);
}
}

static int lua_rng_default(lua_State *L) {
Expand Down
8 changes: 6 additions & 2 deletions src/economy.c
Original file line number Diff line number Diff line change
Expand Up @@ -948,13 +948,17 @@ attrib_allocation(const resource_type * rtype, region * r, allocation * alist)
for (al = alist; al; al = al->next) {
if (avail > 0) {
int want = required(al->want, al->save);
int x = avail * want / nreq;
int rx = (avail * want) % nreq;
long long dx = (long long)avail * want / nreq;
int x, rx = (avail * want) % nreq;

assert(dx < INT_MAX && dx >= 0);
x = (int)dx;
/* Wenn Rest, dann wuerfeln, ob ich was bekomme: */
if (rx > 0 && rng_int() % nreq < rx) ++x;
avail -= x;
nreq -= want;
al->get = x * al->save.sa[1] / al->save.sa[0];
assert(al->get >= 0);
if (al->want < al->get) al->get = al->want;
if (!rtype->raw) {
int use = required(al->get, al->save);
Expand Down
4 changes: 4 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ static int parse_args(int argc, char **argv)
case 'D':
config_set("config.debug", "1");
break;
case 'i':
i = get_arg(argc, argv, 2, i, &arg, 0);
config_set("config.install", arg);
break;
case 'c':
i = get_arg(argc, argv, 2, i, &arg, 0);
config_set("config.path", arg);
Expand Down
Loading