16
16
*/
17
17
18
18
#if defined(LIBC_SCCS )&& !defined(lint )
19
- static const char rcsid []= "$Id: inet_net_pton.c,v 1.3 1998/10/1201:30:26 momjian Exp $" ;
19
+ static const char rcsid []= "$Id: inet_net_pton.c,v 1.4 1998/10/1215:56:34 momjian Exp $" ;
20
20
21
21
#endif
22
22
@@ -105,7 +105,8 @@ inet_net_pton_ipv4(const char *src, u_char *dst, size_t size)
105
105
/* Hexadecimal: Eat nybble string. */
106
106
if (size <=0 )
107
107
gotoemsgsize ;
108
- * dst = 0 ,dirty = 0 ;
108
+ tmp = 0 ;
109
+ dirty = 0 ;
109
110
src ++ ;/* skip x or X. */
110
111
while ((ch = * src ++ )!= '\0' &&
111
112
isascii (ch )&& isxdigit (ch ))
@@ -114,16 +115,20 @@ inet_net_pton_ipv4(const char *src, u_char *dst, size_t size)
114
115
ch = tolower (ch );
115
116
n = strchr (xdigits ,ch )- xdigits ;
116
117
assert (n >=0 && n <=15 );
117
- * dst |=n ;
118
- if (!dirty ++ )
119
- * dst <<=4 ;
120
- else if (-- size > 0 )
121
- * ++ dst = 0 ,dirty = 0 ;
122
- else
118
+ tmp = (tmp <<4 ) |n ;
119
+ if (++ dirty == 2 ) {
120
+ if (size -- <=0 )
121
+ gotoemsgsize ;
122
+ * dst ++ = (u_char )tmp ;
123
+ tmp = 0 ,dirty = 0 ;
124
+ }
125
+ }
126
+ if (dirty ) {
127
+ if (size -- <=0 )
123
128
gotoemsgsize ;
129
+ tmp <<=4 ;
130
+ * dst ++ = (u_char )tmp ;
124
131
}
125
- if (dirty )
126
- size -- ;
127
132
}
128
133
else if (isascii (ch )&& isdigit (ch ))
129
134
{