From 1a174b1828312ceccb366efccbe35c036c678a64 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sun, 20 Apr 2025 09:18:32 +0800 Subject: [PATCH] fix: build warning --- src/maomao.c | 7 ++++++- src/parse_config.h | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/maomao.c b/src/maomao.c index 7f49158..7a410a2 100644 --- a/src/maomao.c +++ b/src/maomao.c @@ -1353,7 +1353,12 @@ pid_t getparentprocess(pid_t p) { if (!(f = fopen(buf, "r"))) return 0; - fscanf(f, "%*u %*s %*c %u", &v); + // 检查fscanf返回值,确保成功读取了1个参数 + if (fscanf(f, "%*u %*s %*c %u", &v) != 1) { + fclose(f); + return 0; + } + fclose(f); return (pid_t)v; diff --git a/src/parse_config.h b/src/parse_config.h index 269a6dd..b5702e2 100644 --- a/src/parse_config.h +++ b/src/parse_config.h @@ -503,9 +503,9 @@ void parse_config_line(Config *config, const char *line) { if (strcmp(key, "animations") == 0) { config->animations = atoi(value); } else if (strcmp(key, "animation_type_open") == 0) { - strncpy(config->animation_type_open, value, sizeof(config->animation_type_open)); + snprintf(config->animation_type_open, sizeof(config->animation_type_open), "%.9s", value); // string limit to 9 char } else if (strcmp(key, "animation_type_close") == 0) { - strncpy(config->animation_type_close, value, sizeof(config->animation_type_close)); + snprintf(config->animation_type_close, sizeof(config->animation_type_close), "%.9s", value); // string limit to 9 char } else if (strcmp(key, "animation_fade_in") == 0) { config->animation_fade_in = atoi(value); } else if (strcmp(key, "zoom_initial_ratio") == 0) {