--- lbbs/src/file_loader.c 2025/06/21 02:15:18 1.15 +++ lbbs/src/file_loader.c 2025/11/04 14:58:56 1.20 @@ -1,18 +1,10 @@ -/*************************************************************************** - file_loader.c - description - ------------------- - Copyright : (C) 2004-2025 by Leaflet - Email : leaflet@leafok.com - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * file_loader + * - shared memory based file loader + * + * Copyright (C) 2004-2025 Leaflet + */ #include "file_loader.h" #include "log.h" @@ -60,7 +52,7 @@ static void trie_file_dict_cleanup_cb(co { int shmid = (int)value; - if (shmctl(shmid, IPC_RMID, NULL) == -1) + if (shmid != 0 && shmctl(shmid, IPC_RMID, NULL) == -1) { log_error("shmctl(shmid=%d, IPC_RMID) error (%d)\n", shmid, errno); } @@ -121,7 +113,7 @@ int load_file(const char *filename) return -1; } - line_total = split_data_lines(p_data, SCREEN_COLS, line_offsets, MAX_SPLIT_FILE_LINES, 1); + line_total = split_data_lines(p_data, SCREEN_COLS, line_offsets, MAX_SPLIT_FILE_LINES, 1, NULL); // Allocate shared memory proj_id = (int)(time(NULL) % getpid()); @@ -149,7 +141,7 @@ int load_file(const char *filename) ((struct shm_header_t *)p_shm)->shmid = shmid; ((struct shm_header_t *)p_shm)->data_len = data_len; ((struct shm_header_t *)p_shm)->line_total = line_total; - memcpy(p_shm + sizeof(struct shm_header_t), p_data, data_len); + memcpy((char *)p_shm + sizeof(struct shm_header_t), p_data, data_len); if (munmap(p_data, data_len) < 0) { @@ -157,8 +149,8 @@ int load_file(const char *filename) return -2; } - p_data = p_shm + sizeof(struct shm_header_t); - p_line_offsets = p_data + data_len + 1; + p_data = (char *)p_shm + sizeof(struct shm_header_t); + p_line_offsets = (long *)((char *)p_data + data_len + 1); memcpy(p_line_offsets, line_offsets, sizeof(long) * (size_t)(line_total + 1)); if (shmdt(p_shm) == -1) @@ -180,7 +172,7 @@ int load_file(const char *filename) { log_error("trie_dict_set(%s) error\n", filename); - if (shmctl(shmid, IPC_RMID, NULL) == -1) + if (shmid != 0 && shmctl(shmid, IPC_RMID, NULL) == -1) { log_error("shmctl(shmid=%d, IPC_RMID) error (%d)\n", shmid, errno); } @@ -241,8 +233,8 @@ const void *get_file_shm_readonly(const *p_data_len = ((struct shm_header_t *)p_shm)->data_len; *p_line_total = ((struct shm_header_t *)p_shm)->line_total; - *pp_data = p_shm + sizeof(struct shm_header_t); - *pp_line_offsets = *pp_data + *p_data_len + 1; + *pp_data = (char *)p_shm + sizeof(struct shm_header_t); + *pp_line_offsets = (const long *)((const char *)(*pp_data) + *p_data_len + 1); return p_shm; }