struct namelist *create_name(char *name);
struct namelist *create_name(char *name)
{
- struct namelist *x = (struct namelist *)calloc(sizeof(struct namelist),1);
- strncpy(x->name,name,100);
+ struct namelist *x = calloc(1, sizeof(*x));
+ if (!x)
+ return NULL;
+ strncpy(x->name, name, sizeof(x->name) - 1);
return x;
}
struct ast_context * ast_context_create(void **extcontexts, const char *name, const char *registrar)
{
- struct ast_context *x = (struct ast_context *)calloc(sizeof(struct ast_context),1);
+ struct ast_context *x = calloc(1, sizeof(*x));
+ if (!x)
+ return NULL;
x->next = context_list;
context_list = x;
- if(!no_comp)
+ if (!no_comp)
printf("Executed ast_context_create(conts, name=%s, registrar=%s);\n", name, registrar);
conts++;
- strncpy(x->name,name,100);
- strncpy(x->registrar,registrar,100);
+ strncpy(x->name, name, sizeof(x->name) - 1);
+ strncpy(x->registrar, registrar, sizeof(x->registrar) - 1);
return x;
}
chan = malloc(sizeof(struct channel));
if (chan) {
memset(chan, 0, sizeof(struct channel));
- chan->tech = strdup(tech);
- chan->location = strdup(location);
+ if (!(chan->tech = strdup(tech))) {
+ free(chan);
+ return;
+ }
+ if (!(chan->location = strdup(location))) {
+ free(chan->tech);
+ free(chan);
+ return;
+ }
chan->next = channels;
channels = chan;
}
sub = malloc(sizeof(struct subchannel));
if (sub) {
memset(sub, 0, sizeof(struct subchannel));
- sub->name = strdup(name);
+ if (!(sub->name = strdup(name))) {
+ free(sub);
+ return;
+ }
sub->next = chan->subs;
chan->subs = sub;
}