mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibC: Use FlatPtr for malloced char* address storage
This would break with the next commit, after which char* will always be treated as c-strings.
This commit is contained in:
parent
ceb0e28ea5
commit
dea86f511c
Notes:
sideshowbarker
2024-07-17 22:46:59 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/dea86f511ce Pull-request: https://github.com/SerenityOS/serenity/pull/10808 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/linusg Reviewed-by: https://github.com/trflynn89 ✅
1 changed files with 4 additions and 4 deletions
|
@ -222,14 +222,14 @@ void abort()
|
||||||
_abort();
|
_abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
static HashTable<const char*> s_malloced_environment_variables;
|
static HashTable<FlatPtr> s_malloced_environment_variables;
|
||||||
|
|
||||||
static void free_environment_variable_if_needed(const char* var)
|
static void free_environment_variable_if_needed(const char* var)
|
||||||
{
|
{
|
||||||
if (!s_malloced_environment_variables.contains(var))
|
if (!s_malloced_environment_variables.contains((FlatPtr)var))
|
||||||
return;
|
return;
|
||||||
free(const_cast<char*>(var));
|
free(const_cast<char*>(var));
|
||||||
s_malloced_environment_variables.remove(var);
|
s_malloced_environment_variables.remove((FlatPtr)var);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* getenv(const char* name)
|
char* getenv(const char* name)
|
||||||
|
@ -304,7 +304,7 @@ int setenv(const char* name, const char* value, int overwrite)
|
||||||
auto length = strlen(name) + strlen(value) + 2;
|
auto length = strlen(name) + strlen(value) + 2;
|
||||||
auto* var = (char*)malloc(length);
|
auto* var = (char*)malloc(length);
|
||||||
snprintf(var, length, "%s=%s", name, value);
|
snprintf(var, length, "%s=%s", name, value);
|
||||||
s_malloced_environment_variables.set(var);
|
s_malloced_environment_variables.set((FlatPtr)var);
|
||||||
return putenv(var);
|
return putenv(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue