3939#endif
4040#include "picohttpparser.h"
4141
42- /* $Id$ */
43-
4442#if __GNUC__ >= 3
4543#define likely (x ) __builtin_expect(!!(x), 1)
4644#define unlikely (x ) __builtin_expect(!!(x), 0)
@@ -169,9 +167,9 @@ static const char *findchar_nonprintable_fast(const char *buf, const char *buf_e
169167
170168 return buf ;
171169#else
172- static const char ALIGNED (16 ) ranges2 [] = "\000\040\177\177" ;
170+ static const char ALIGNED (16 ) ranges2 [16 ] = "\000\040\177\177" ;
173171
174- return findchar_fast (buf , buf_end , ranges2 , sizeof ( ranges2 ) - 1 , found );
172+ return findchar_fast (buf , buf_end , ranges2 , 4 , found );
175173#endif
176174}
177175
@@ -180,15 +178,11 @@ static const char *get_token_to_eol(const char *buf, const char *buf_end, const
180178 const char * token_start = buf ;
181179
182180#ifdef __SSE4_2__
183- static const char ranges1 [] = "\0\010"
184- /* allow HT */
185- "\012\037"
186- /* allow SP and up to but not including DEL */
187- "\177\177"
188- /* allow chars w. MSB set */
189- ;
181+ static const char ALIGNED (16 ) ranges1 [16 ] = "\0\010" /* allow HT */
182+ "\012\037" /* allow SP and up to but not including DEL */
183+ "\177\177" ; /* allow chars w. MSB set */
190184 int found ;
191- buf = findchar_fast (buf , buf_end , ranges1 , sizeof ( ranges1 ) - 1 , & found );
185+ buf = findchar_fast (buf , buf_end , ranges1 , 6 , & found );
192186 if (found )
193187 goto FOUND_CTL ;
194188#elif defined(__ARM_64BIT_STATE ) && defined(__ARM_FEATURE_UNALIGNED ) && !defined(__ARM_BIG_ENDIAN )
@@ -433,9 +427,13 @@ static const char *parse_request(const char *buf, const char *buf_end, const cha
433427
434428 /* parse request line */
435429 ADVANCE_TOKEN (* method , * method_len );
436- ++ buf ;
430+ do {
431+ ++ buf ;
432+ } while (* buf == ' ' );
437433 ADVANCE_TOKEN (* path , * path_len );
438- ++ buf ;
434+ do {
435+ ++ buf ;
436+ } while (* buf == ' ' );
439437 if (* method_len == 0 || * path_len == 0 ) {
440438 * ret = -1 ;
441439 return NULL ;
@@ -492,10 +490,13 @@ static const char *parse_response(const char *buf, const char *buf_end, int *min
492490 return NULL ;
493491 }
494492 /* skip space */
495- if (* buf ++ != ' ' ) {
493+ if (* buf != ' ' ) {
496494 * ret = -1 ;
497495 return NULL ;
498496 }
497+ do {
498+ ++ buf ;
499+ } while (* buf == ' ' );
499500 /* parse status code, we want at least [:digit:][:digit:][:digit:]<other char> to try to parse */
500501 if (buf_end - buf < 4 ) {
501502 * ret = -2 ;
@@ -511,8 +512,10 @@ static const char *parse_response(const char *buf, const char *buf_end, int *min
511512 /* ok */
512513 } else if (* * msg == ' ' ) {
513514 /* remove preceding space */
514- ++ * msg ;
515- -- * msg_len ;
515+ do {
516+ ++ * msg ;
517+ -- * msg_len ;
518+ } while (* * msg == ' ' );
516519 } else {
517520 /* garbage found after status code */
518521 * ret = -1 ;
0 commit comments