udhcp: code shrink

function                                             old     new   delta
attach_option                                        406     349     -57

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2019-01-07 15:23:18 +01:00
parent edca770d11
commit b80bdeba02

View File

@ -422,6 +422,7 @@ static NOINLINE void attach_option(
if (errno) if (errno)
bb_error_msg_and_die("malformed hex string '%s'", buffer); bb_error_msg_and_die("malformed hex string '%s'", buffer);
length = end - allocated; length = end - allocated;
buffer = allocated;
} }
#if ENABLE_FEATURE_UDHCP_RFC3397 #if ENABLE_FEATURE_UDHCP_RFC3397
if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) { if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) {
@ -441,15 +442,14 @@ static NOINLINE void attach_option(
new->data = xmalloc(length + OPT_DATA); new->data = xmalloc(length + OPT_DATA);
new->data[OPT_CODE] = optflag->code; new->data[OPT_CODE] = optflag->code;
new->data[OPT_LEN] = length; new->data[OPT_LEN] = length;
memcpy(new->data + OPT_DATA, (allocated ? allocated : buffer), memcpy(new->data + OPT_DATA, buffer, length);
length);
} else { } else {
new->data = xmalloc(length + D6_OPT_DATA); new->data = xmalloc(length + D6_OPT_DATA);
new->data[D6_OPT_CODE] = optflag->code >> 8; new->data[D6_OPT_CODE] = optflag->code >> 8;
new->data[D6_OPT_CODE + 1] = optflag->code & 0xff; new->data[D6_OPT_CODE + 1] = optflag->code & 0xff;
new->data[D6_OPT_LEN] = length >> 8; new->data[D6_OPT_LEN] = length >> 8;
new->data[D6_OPT_LEN + 1] = length & 0xff; new->data[D6_OPT_LEN + 1] = length & 0xff;
memcpy(new->data + D6_OPT_DATA, (allocated ? allocated : buffer), memcpy(new->data + D6_OPT_DATA, buffer,
length); length);
} }
@ -472,6 +472,8 @@ static NOINLINE void attach_option(
/* actually 255 is ok too, but adding a space can overlow it */ /* actually 255 is ok too, but adding a space can overlow it */
existing->data = xrealloc(existing->data, OPT_DATA + 1 + old_len + length); existing->data = xrealloc(existing->data, OPT_DATA + 1 + old_len + length);
// So far dhcp_optflags[] has no OPTION_STRING[_HOST] | OPTION_LIST items
#if 0
if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING
|| (optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING_HOST || (optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING_HOST
) { ) {
@ -479,7 +481,9 @@ static NOINLINE void attach_option(
existing->data[OPT_DATA + old_len] = ' '; existing->data[OPT_DATA + old_len] = ' ';
old_len++; old_len++;
} }
memcpy(existing->data + OPT_DATA + old_len, (allocated ? allocated : buffer), length); #endif
memcpy(existing->data + OPT_DATA + old_len, buffer, length);
existing->data[OPT_LEN] = old_len + length; existing->data[OPT_LEN] = old_len + length;
} /* else, ignore the data, we could put this in a second option in the future */ } /* else, ignore the data, we could put this in a second option in the future */
} /* else, ignore the new data */ } /* else, ignore the new data */