]> Lady’s Gitweb - CGirls/blobdiff - request.c
Drop `assert()´ check in subpath parsing
[CGirls] / request.c
index b868812c9f1fd89a1afd8a1e65182248203d87cf..f9fa453a85931e48326a6eb96c9ea57b718d6ae0 100644 (file)
--- a/request.c
+++ b/request.c
@@ -164,10 +164,13 @@ cgirls_req cgirls_path·to·req(char const*const pathinfo) {
        // The portion of the pathinfo which follows the third slash is the
        // subpath of the request. An empty sting is equivalent to having no
        // subpath. Trailing and successive slashes are dropped.
-       char const* sos = ndx[0];
        char const* sep = nullptr;
        size_t n·s = 0;
-       while (end[0] > sos) {
+       for (
+               char const* sos = ndx[0];
+               sos < end[0];
+               sos = (end[0] > sep ? sep + 1 : end[0])
+       ) {
                // Count the number of segments in the pathinfo so that the correct
                // amount of space can be allocated.
                sep = strchr(sos, '/');
@@ -177,34 +180,28 @@ cgirls_req cgirls_path·to·req(char const*const pathinfo) {
                if (sep > sos) {
                        ++n·s;
                }
-               if (end[0] > sep) {
-                       sos = sep + 1;
-               } else {
-                       sos = end[0];
-               }
-       }
-       req.subpath = calloc(n·s + 1, sizeof(char*));
-       if (!req.subpath) {
-               return req;
        }
-       size_t i·s = 0;
-       while (end[0] > ndx[0]) {
-               // Add the segments to the newly allocated array.
-               sep = strchr(ndx[0], '/');
-               if (!sep) {
-                       sep = end[0];
+       if (n·s > 0) {
+               req.subpath = calloc(n·s + 1, sizeof(char*));
+               if (!req.subpath) {
+                       return req;
                }
-               if (sep > ndx[0]) {
-                       req.subpath[i·s++] = strndup(ndx[0], sep - ndx[0]);
-               }
-               if (end[0] > sep) {
-                       ndx[0] = sep + 1;
-               } else {
-                       ndx[0] = end[0];
+               for (
+                       size_t i·s = 0;
+                       i·s < n·s;
+                       ndx[0] = (end[0] > sep ? sep + 1 : end[0])
+               ) {
+                       // Add the segments to the newly allocated array.
+                       sep = strchr(ndx[0], '/');
+                       if (!sep) {
+                               sep = end[0];
+                       }
+                       if (sep > ndx[0]) {
+                               req.subpath[i·s++] = strndup(ndx[0], sep - ndx[0]);
+                       }
                }
+               req.subpath[n·s] = nullptr;
        }
-       assert(i·s == n·s);
-       req.subpath[i·s] = nullptr;
 
        // Return the result.
        return req;
This page took 0.028542 seconds and 4 git commands to generate.