1616 */
1717
1818#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 $" ;
2020
2121#endif
2222
@@ -105,7 +105,8 @@ inet_net_pton_ipv4(const char *src, u_char *dst, size_t size)
105105/* Hexadecimal: Eat nybble string. */
106106if (size <=0 )
107107gotoemsgsize ;
108- * dst = 0 ,dirty = 0 ;
108+ tmp = 0 ;
109+ dirty = 0 ;
109110src ++ ;/* skip x or X. */
110111while ((ch = * src ++ )!= '\0' &&
111112isascii (ch )&& isxdigit (ch ))
@@ -114,16 +115,20 @@ inet_net_pton_ipv4(const char *src, u_char *dst, size_t size)
114115ch = tolower (ch );
115116n = strchr (xdigits ,ch )- xdigits ;
116117assert (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 )
123128gotoemsgsize ;
129+ tmp <<=4 ;
130+ * dst ++ = (u_char )tmp ;
124131}
125- if (dirty )
126- size -- ;
127132}
128133else if (isascii (ch )&& isdigit (ch ))
129134{