Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/ntp/libntp/hextolfp.c
Show All 31 Lines | hextolfp( | ||||
*/ | */ | ||||
while (isspace((unsigned char)*cp)) | while (isspace((unsigned char)*cp)) | ||||
cp++; | cp++; | ||||
cpstart = cp; | cpstart = cp; | ||||
while (*cp != '\0' && (cp - cpstart) < 8 && | while (*cp != '\0' && (cp - cpstart) < 8 && | ||||
(ind = strchr(digits, *cp)) != NULL) { | (ind = strchr(digits, *cp)) != NULL) { | ||||
dec_i = dec_i << 4; /* multiply by 16 */ | dec_i = dec_i << 4; /* multiply by 16 */ | ||||
dec_i += ((ind - digits) > 15) ? (ind - digits) - 6 | dec_i += ((ind - digits) > 15) | ||||
: (ind - digits); | ? (u_long)(ind - digits - 6) | ||||
: (u_long)(ind - digits); | |||||
cp++; | cp++; | ||||
} | } | ||||
if ((cp - cpstart) < 8 || ind == NULL) | if ((cp - cpstart) < 8 || ind == NULL) | ||||
return 0; | return 0; | ||||
if (*cp == '.') | if (*cp == '.') | ||||
cp++; | cp++; | ||||
cpstart = cp; | cpstart = cp; | ||||
while (*cp != '\0' && (cp - cpstart) < 8 && | while (*cp != '\0' && (cp - cpstart) < 8 && | ||||
(ind = strchr(digits, *cp)) != NULL) { | (ind = strchr(digits, *cp)) != NULL) { | ||||
dec_f = dec_f << 4; /* multiply by 16 */ | dec_f = dec_f << 4; /* multiply by 16 */ | ||||
dec_f += ((ind - digits) > 15) ? (ind - digits) - 6 | dec_f += ((ind - digits) > 15) | ||||
: (ind - digits); | ? (u_long)(ind - digits - 6) | ||||
: (u_long)(ind - digits); | |||||
cp++; | cp++; | ||||
} | } | ||||
if ((cp - cpstart) < 8 || ind == NULL) | if ((cp - cpstart) < 8 || ind == NULL) | ||||
return 0; | return 0; | ||||
if (*cp != '\0' && !isspace((unsigned char)*cp)) | if (*cp != '\0' && !isspace((unsigned char)*cp)) | ||||
return 0; | return 0; | ||||
lfp->l_ui = dec_i; | lfp->l_ui = dec_i; | ||||
lfp->l_uf = dec_f; | lfp->l_uf = dec_f; | ||||
return 1; | return 1; | ||||
} | } |