2 次代码提交 094bf112bb ... 6d848d4bfc

作者 SHA1 备注 提交日期
  yhirose 6d848d4bfc Fix warning 4 天之前
  yhirose 117f28f977 Fix problems with CPPHTTPLIB_NO_EXCEPTIONS 4 天之前
共有 2 个文件被更改,包括 35 次插入4 次删除
  1. 32 3
      httplib.h
  2. 3 1
      test/test.cc

+ 32 - 3
httplib.h

@@ -3264,7 +3264,9 @@ private:
 #ifdef CPPHTTPLIB_NO_EXCEPTIONS
       {
         std::istringstream iss(value);
-        iss >> retry_ms;
+        int v;
+        iss >> v;
+        if (!iss.fail()) { retry_ms = v; }
       }
 #else
       try {
@@ -6335,10 +6337,35 @@ inline bool parse_range_header(const std::string &s, Ranges &ranges) try {
         return;
       }
 
+#ifdef CPPHTTPLIB_NO_EXCEPTIONS
+      ssize_t first = -1;
+      ssize_t last = -1;
+      if (!lhs.empty()) {
+        std::istringstream iss(lhs);
+        long long v;
+        iss >> v;
+        if (iss.fail() || !iss.eof()) {
+          all_valid_ranges = false;
+          return;
+        }
+        first = static_cast<ssize_t>(v);
+      }
+      if (!rhs.empty()) {
+        std::istringstream iss(rhs);
+        long long v;
+        iss >> v;
+        if (iss.fail() || !iss.eof()) {
+          all_valid_ranges = false;
+          return;
+        }
+        last = static_cast<ssize_t>(v);
+      }
+#else
       const auto first =
           static_cast<ssize_t>(lhs.empty() ? -1 : std::stoll(lhs));
       const auto last =
           static_cast<ssize_t>(rhs.empty() ? -1 : std::stoll(rhs));
+#endif
       if ((first == -1 && last == -1) ||
           (first != -1 && last != -1 && first > last)) {
         all_valid_ranges = false;
@@ -13376,8 +13403,10 @@ inline bool SSLClient::check_host_name(const char *pattern,
           partial_match = true;
         } else if (h.size() >= prefix_length) {
           partial_match =
-              std::equal(p.begin(), p.begin() + prefix_length, h.begin(),
-                         [](const char ca, const char cb) {
+              std::equal(p.begin(),
+                         p.begin() + static_cast<std::string::difference_type>(
+                                         prefix_length),
+                         h.begin(), [](const char ca, const char cb) {
                            return httplib::detail::case_ignore::to_lower(ca) ==
                                   httplib::detail::case_ignore::to_lower(cb);
                          });

+ 3 - 1
test/test.cc

@@ -13568,7 +13568,9 @@ protected:
 #ifdef CPPHTTPLIB_NO_EXCEPTIONS
       {
         std::istringstream iss(value);
-        iss >> retry_ms;
+        int v;
+        iss >> v;
+        if (!iss.fail()) { retry_ms = v; }
       }
 #else
       try {