@@ -152,8 +152,7 @@ static void init_conn(int efd, struct econn *ec)
152
152
}
153
153
154
154
struct epoll_event evt = {
155
- .events = EPOLLOUT ,
156
- .data .ptr = ec ,
155
+ .events = EPOLLOUT , .data .ptr = ec ,
157
156
};
158
157
159
158
if (epoll_ctl (efd , EPOLL_CTL_ADD , ec -> fd , & evt )) {
@@ -430,14 +429,16 @@ int main(int argc, char *argv[])
430
429
* rq ++ = 0 ;
431
430
port = rq ;
432
431
rq = strchr (rq , '/' );
433
- if (* rq == '/' ) {
434
- port = strndup (port , rq - port );
435
- if (!port ) {
436
- perror ("port = strndup(rq, rq - port)" );
437
- exit (EXIT_FAILURE );
438
- }
439
- } else
440
- rq = "/" ;
432
+ if (rq ) {
433
+ if (* rq == '/' ) {
434
+ port = strndup (port , rq - port );
435
+ if (!port ) {
436
+ perror ("port = strndup(rq, rq - port)" );
437
+ exit (EXIT_FAILURE );
438
+ }
439
+ } else
440
+ rq = "/" ;
441
+ }
441
442
}
442
443
443
444
if (strnlen (udaddr , sizeof (ssun -> sun_path ) - 1 ) == 0 ) {
@@ -487,9 +488,12 @@ int main(int argc, char *argv[])
487
488
/* prepare request buffer */
488
489
if (!host )
489
490
host = node ;
490
- outbufsize = strlen (rq ) + sizeof (HTTP_REQUEST_FMT ) + strlen (host );
491
+ outbufsize = sizeof (HTTP_REQUEST_FMT ) + strlen (host );
492
+ outbufsize += rq ? strlen (rq ) : 1 ;
493
+
491
494
outbuf = malloc (outbufsize );
492
- outbufsize = snprintf (outbuf , outbufsize , HTTP_REQUEST_FMT , rq , host );
495
+ outbufsize =
496
+ snprintf (outbuf , outbufsize , HTTP_REQUEST_FMT , rq ? rq : "/" , host );
493
497
494
498
ticks = max_requests / 10 ;
495
499
0 commit comments