mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
stk(3): fix argument type of exception callback function
The callback function for malloc(3) failure in the stk(3) routines (which can be specified using stkinstall() and is set to nomemory() in init.c) uses a size argument of type int. That's a type mismatch with all the other size arguments and variables in stk(3) which use size_t, an unsigned type that may be larger than int. This is all quite inconsequential as nothing in our code base (or in the complete old AT&T AST code base) actually uses that size for anything, but it's still wrong, so this corrects the interface. With this very minor API change, let's bump the libast API version to 20220801, the date of the upcoming ksh 93u+m 1.0.0 release. :) The ksh93/sh/init.c nomemory() function now reports the size that could not be allocated, just because it can.
This commit is contained in:
parent
9f6841c37e
commit
3e84231558
7 changed files with 45 additions and 23 deletions
|
|
@ -30,8 +30,8 @@
|
|||
#endif
|
||||
|
||||
#include <ast.h>
|
||||
#if !defined(AST_VERSION) || AST_VERSION < 20220208
|
||||
#error libast version 20220208 or later is required
|
||||
#if !defined(AST_VERSION) || AST_VERSION < 20220801
|
||||
#error libast version 20220801 or later is required
|
||||
#endif
|
||||
#if !_lib_fork
|
||||
#error In 2021, ksh joined the 21st century and started requiring fork(2).
|
||||
|
|
|
|||
|
|
@ -222,12 +222,11 @@ static int shlvl;
|
|||
static int rand_shift;
|
||||
|
||||
/*
|
||||
* out of memory routine for stak routines
|
||||
* Exception callback routine for stk(3)/stak(3) and sh_*alloc wrappers.
|
||||
*/
|
||||
static noreturn char *nomemory(int unused)
|
||||
static noreturn char *nomemory(size_t s)
|
||||
{
|
||||
NOT_USED(unused);
|
||||
errormsg(SH_DICT, ERROR_SYSTEM|ERROR_PANIC, "out of memory");
|
||||
errormsg(SH_DICT, ERROR_SYSTEM|ERROR_PANIC, "out of memory (needed %llu bytes)", (uintmax_t)s);
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
|
|
@ -239,7 +238,7 @@ void *sh_malloc(size_t size)
|
|||
{
|
||||
void *cp = malloc(size);
|
||||
if(!cp)
|
||||
nomemory(0);
|
||||
nomemory(size);
|
||||
return(cp);
|
||||
}
|
||||
|
||||
|
|
@ -247,7 +246,7 @@ void *sh_realloc(void *ptr, size_t size)
|
|||
{
|
||||
void *cp = realloc(ptr, size);
|
||||
if(!cp)
|
||||
nomemory(0);
|
||||
nomemory(size);
|
||||
return(cp);
|
||||
}
|
||||
|
||||
|
|
@ -255,7 +254,7 @@ void *sh_calloc(size_t nmemb, size_t size)
|
|||
{
|
||||
void *cp = calloc(nmemb, size);
|
||||
if(!cp)
|
||||
nomemory(0);
|
||||
nomemory(size);
|
||||
return(cp);
|
||||
}
|
||||
|
||||
|
|
@ -263,7 +262,7 @@ char *sh_strdup(const char *s)
|
|||
{
|
||||
char *dup = strdup(s);
|
||||
if(!dup)
|
||||
nomemory(0);
|
||||
nomemory(strlen(s)+1);
|
||||
return(dup);
|
||||
}
|
||||
|
||||
|
|
@ -271,7 +270,7 @@ void *sh_memdup(const void *s, size_t n)
|
|||
{
|
||||
void *dup = memdup(s, n);
|
||||
if(!dup)
|
||||
nomemory(0);
|
||||
nomemory(n);
|
||||
return(dup);
|
||||
}
|
||||
|
||||
|
|
@ -279,7 +278,7 @@ char *sh_getcwd(void)
|
|||
{
|
||||
char *cwd = getcwd(NIL(char*), 0);
|
||||
if(!cwd && errno==ENOMEM)
|
||||
nomemory(0);
|
||||
nomemory(PATH_MAX);
|
||||
return(cwd);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue