diff --git a/src/chsrc-main.c b/src/chsrc-main.c index ec9679edf..d888f0fd4 100644 --- a/src/chsrc-main.c +++ b/src/chsrc-main.c @@ -93,6 +93,9 @@ chsrc_register_chefs_and_sauciers () chef_register_contributor ("@JIAFALSEDREAM", "假发", "jiafa@hello-happy.world", NULL); chef_register_contributor ("@yayoinoyume", "YAYOI27", "yayoi27@yayoi.uk", NULL); + chef_register_contributor ("@lilyco-42", "Haoyu Zhou", "", "lilyco-42"); + chef_register_contributor ("@YuruiHong", "Yurui Hong", "", "YuruiHong"); + /** * AI贡献者: * diff --git a/src/framework/source.c b/src/framework/source.c index 50bb6b0d6..5239ff800 100644 --- a/src/framework/source.c +++ b/src/framework/source.c @@ -8,9 +8,10 @@ * | @BingChunMoLi * | @Mikachu2333 * | @JIAFALSEDREAM + * | @lilyco-42 * | * Created On : <2023-08-29> - * Last Modified : <2026-08-20> + * Last Modified : <2026-11-29> * * 源的确定 * ------------------------------------------------------------*/ @@ -112,9 +113,31 @@ measure_speed_for_url (void *url) static double parse_and_say_curl_result (char *curl_buf) { + /* curl 失败时可能无任何输出,此时须软处理而非崩溃。 + * 理论上走不到这里:一旦触发,说明我们正在排查的 Bug 真实发生,请让用户报告以便定位。 */ + if (NULL==curl_buf || '\0'==curl_buf[0]) + { + char *msg = ENGLISH + ? "ERROR curl output is empty (connection failed?). This is a bug under investigation, please report: chsrc issue" + : "错误 curl 无输出 (连接失败?)。这是我们正在排查的 Bug,请报告以便定位: chsrc issue"; + println (red (msg)); + return -1; + } + /* 分隔两部分数据 */ char *split = strchr (curl_buf, ' '); - if (split) *split = '\0'; + if (NULL==split) + { + /* 输出不含空格,格式异常,软处理;同样请用户报告以便定位正在排查的 Bug */ + char *msg = ENGLISH ? "ERROR malformed curl output: " : "错误 curl 输出格式异常: "; + char *report = ENGLISH + ? " (This is a bug under investigation, please report: chsrc issue)" + : "(这是我们正在排查的 Bug,请报告以便定位: chsrc issue)"; + println (red (xy_strcat (3, msg, curl_buf, report))); + return -1; + } + + *split = '\0'; // say(curl_buf); say(split+1); int http_code = xy_str2int (curl_buf); diff --git a/test/fw.c b/test/fw.c index bcceb18b9..c8d6e32ac 100644 --- a/test/fw.c +++ b/test/fw.c @@ -13,6 +13,9 @@ #include "../src/framework/base.c" #include "../src/framework/OS.c" +#include "../src/framework/dish.c" +#include "../src/framework/chef.c" +#include "../src/framework/source.c" int main (int argc, char const *argv[]) @@ -25,6 +28,17 @@ main (int argc, char const *argv[]) xy_init (); + char empty[] = ""; + char malformed[] = "000"; + char failed[] = "000 0"; + char normal[] = "200 1024"; + assert (parse_and_say_curl_result (NULL) == -1); + assert (parse_and_say_curl_result (empty) == -1); + assert (parse_and_say_curl_result (malformed) == -1); + assert (parse_and_say_curl_result (failed) == 0); + assert (parse_and_say_curl_result (normal) == 1024); + + br(); chsrc_log ("chsrc_log"); chsrc_succ ("chsrc_succ");