check allocation and return some other error codes too
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8291 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
47
lib/sl/ss.c
47
lib/sl/ss.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1998 Kungliga Tekniska H<>gskolan
|
||||
* Copyright (c) 1998 - 2000 Kungliga Tekniska H<>gskolan
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -55,14 +55,34 @@ ss_create_invocation(const char *subsystem,
|
||||
int *code)
|
||||
{
|
||||
struct ss_subst *ss;
|
||||
|
||||
if(num_subsystems >= sizeof(subsystems) / sizeof(subsystems[0])) {
|
||||
*code = 17;
|
||||
return 0;
|
||||
}
|
||||
ss = &subsystems[num_subsystems];
|
||||
ss->name = subsystem ? strdup(subsystem) : NULL;
|
||||
ss->version = version ? strdup(version) : NULL;
|
||||
ss->info = info ? strdup(info) : NULL;
|
||||
ss->name = ss->version = ss->info = NULL;
|
||||
if (subsystem != NULL) {
|
||||
ss->name = strdup (subsystem);
|
||||
if (ss->name == NULL) {
|
||||
*code = ENOMEM;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (version != NULL) {
|
||||
ss->version = strdup (version);
|
||||
if (ss->version == NULL) {
|
||||
*code = ENOMEM;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (info != NULL) {
|
||||
ss->info = strdup (info);
|
||||
if (ss->info == NULL) {
|
||||
*code = ENOMEM;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
ss->table = table;
|
||||
*code = 0;
|
||||
return num_subsystems++;
|
||||
@@ -87,8 +107,12 @@ int
|
||||
ss_execute_command(int index, char **argv)
|
||||
{
|
||||
int argc = 0;
|
||||
int ret;
|
||||
|
||||
while(argv[argc++]);
|
||||
sl_command(subsystems[index].table, argc, argv);
|
||||
ret = sl_command(subsystems[index].table, argc, argv);
|
||||
if (ret == SL_BADCOMMAND)
|
||||
return SS_ET_COMMAND_NOT_FOUND;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -98,10 +122,15 @@ ss_execute_line (int index, const char *line)
|
||||
char *buf = strdup(line);
|
||||
int argc;
|
||||
char **argv;
|
||||
int ret;
|
||||
|
||||
if (buf == NULL)
|
||||
return ENOMEM;
|
||||
sl_make_argv(buf, &argc, &argv);
|
||||
sl_command(subsystems[index].table, argc, argv);
|
||||
ret = sl_command(subsystems[index].table, argc, argv);
|
||||
free(buf);
|
||||
if (ret == SL_BADCOMMAND)
|
||||
return SS_ET_COMMAND_NOT_FOUND;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -109,9 +138,9 @@ int
|
||||
ss_listen (int index)
|
||||
{
|
||||
char *prompt = malloc(strlen(subsystems[index].name) + 3);
|
||||
if(prompt == NULL) {
|
||||
abort();
|
||||
}
|
||||
if (prompt = NULL)
|
||||
return ENOMEM;
|
||||
|
||||
strcpy(prompt, subsystems[index].name);
|
||||
strcat(prompt, ": ");
|
||||
sl_loop(subsystems[index].table, prompt);
|
||||
|
Reference in New Issue
Block a user