/* Use "memcpy" for pointer assignments here to avoid problems
* with C99 strict type aliasing rules. */
memcpy(&p, ptr, sizeof (p));
- p = realloc(p, size);
- if (!p)
- return EXT2_ET_NO_MEMORY;
+ p = xrealloc(p, size);
memcpy(ptr, &p, sizeof (p));
return 0;
}
{
struct fs_info *fs;
- if (!(fs = malloc(sizeof(struct fs_info))))
- return NULL;
+ fs = xmalloc(sizeof(struct fs_info));
fs->device = string_copy(device);
fs->mountpt = string_copy(mntpnt);
struct fsck_instance *inst, *p;
pid_t pid;
- inst = malloc(sizeof(struct fsck_instance));
- if (!inst)
- return ENOMEM;
- memset(inst, 0, sizeof(struct fsck_instance));
+ inst = xzalloc(sizeof(struct fsck_instance));
prog = xasprintf("fsck.%s", type);
argv[0] = prog;
* structure and use that. Link it in in place of
* the old line structure.
*/
- nlp = malloc(sizeof(LINE) + lp->len + deltaLen);
- if (nlp == NULL) {
- bb_error_msg("can't get memory for line");
- return;
- }
+ nlp = xmalloc(sizeof(LINE) + lp->len + deltaLen);
nlp->len = lp->len + deltaLen;
if (bufUsed >= bufSize) {
len = (bufSize * 3) / 2;
- cp = realloc(bufBase, len);
- if (cp == NULL) {
- bb_error_msg("no memory for buffer");
- close(fd);
- return FALSE;
- }
+ cp = xrealloc(bufBase, len);
bufBase = cp;
bufPtr = bufBase + bufUsed;
bufSize = len;
return FALSE;
}
- newLp = malloc(sizeof(LINE) + len - 1);
- if (newLp == NULL) {
- bb_error_msg("failed to allocate memory for line");
- return FALSE;
- }
+ newLp = xmalloc(sizeof(LINE) + len - 1);
memcpy(newLp->data, data, len);
newLp->len = len;
/* append next_line, read new next_line. */
}
len = strlen(pattern_space);
- pattern_space = realloc(pattern_space, len + strlen(next_line) + 2);
+ pattern_space = xrealloc(pattern_space, len + strlen(next_line) + 2);
pattern_space[len] = '\n';
strcpy(pattern_space + len+1, next_line);
last_gets_char = next_gets_char;
static NOINLINE int print_linkinfo(const struct nlmsghdr *n)
{
struct ifinfomsg *ifi = NLMSG_DATA(n);
- struct rtattr * tb[IFLA_MAX+1];
+ struct rtattr *tb[IFLA_MAX+1];
int len = n->nlmsg_len;
- unsigned m_flag = 0;
if (n->nlmsg_type != RTM_NEWLINK && n->nlmsg_type != RTM_DELLINK)
return 0;
printf("Deleted ");
printf("%d: %s", ifi->ifi_index,
- tb[IFLA_IFNAME] ? (char*)RTA_DATA(tb[IFLA_IFNAME]) : "<nil>");
-
- if (tb[IFLA_LINK]) {
- SPRINT_BUF(b1);
- int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]);
- if (iflink == 0)
- printf("@NONE: ");
- else {
- printf("@%s: ", ll_idx_n2a(iflink, b1));
- m_flag = ll_index_to_flags(iflink);
- m_flag = !(m_flag & IFF_UP);
+ /*tb[IFLA_IFNAME] ? (char*)RTA_DATA(tb[IFLA_IFNAME]) : "<nil>" - we checked tb[IFLA_IFNAME] above*/
+ (char*)RTA_DATA(tb[IFLA_IFNAME])
+ );
+
+ {
+ unsigned m_flag = 0;
+ if (tb[IFLA_LINK]) {
+ SPRINT_BUF(b1);
+ int iflink = *(int*)RTA_DATA(tb[IFLA_LINK]);
+ if (iflink == 0)
+ printf("@NONE: ");
+ else {
+ printf("@%s: ", ll_idx_n2a(iflink, b1));
+ m_flag = ll_index_to_flags(iflink);
+ m_flag = !(m_flag & IFF_UP);
+ }
+ } else {
+ printf(": ");
}
- } else {
- printf(": ");
+ print_link_flags(ifi->ifi_flags, m_flag);
}
- print_link_flags(ifi->ifi_flags, m_flag);
if (tb[IFLA_MTU])
printf("mtu %u ", *(int*)RTA_DATA(tb[IFLA_MTU]));
struct nlmsg_list *h;
struct nlmsg_list **lp;
- h = malloc(n->nlmsg_len+sizeof(void*));
- if (h == NULL)
- return -1;
+ h = xzalloc(n->nlmsg_len + sizeof(void*));
memcpy(&h->h, n, n->nlmsg_len);
- h->next = NULL;
+ /*h->next = NULL; - xzalloc did it */
for (lp = linfo; *lp; lp = &(*lp)->next)
continue;