/[LeafOK_CVS]/lbbs/src/memory_pool.c
ViewVC logotype

Diff of /lbbs/src/memory_pool.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.5 by sysadm, Sat Jun 21 02:15:18 2025 UTC Revision 1.9 by sysadm, Tue Nov 11 00:28:05 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                                  memory_pool.c  -  description  /*
3                                                           -------------------   * memory_pool
4          copyright            : (C) 2004-2025 by Leaflet   *   - memory pool
5          email                : leaflet@leafok.com   *
6   ***************************************************************************/   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "log.h"  #include "log.h"
14  #include "memory_pool.h"  #include "memory_pool.h"
# Line 98  inline static void *memory_pool_add_chun Line 94  inline static void *memory_pool_add_chun
94          }          }
95    
96          p_node = p_pool->p_free;          p_node = p_pool->p_free;
97          memcpy(p_chunk + (p_pool->node_count_per_chunk - 1) * p_pool->node_size, &p_node, sizeof(p_node));          memcpy((char *)p_chunk + (p_pool->node_count_per_chunk - 1) * p_pool->node_size, &p_node, sizeof(p_node));
98          for (i = 0; i < p_pool->node_count_per_chunk - 1; i++)          for (i = 0; i < p_pool->node_count_per_chunk - 1; i++)
99          {          {
100                  p_node = p_chunk + (i + 1) * p_pool->node_size;                  p_node = (char *)p_chunk + (i + 1) * p_pool->node_size;
101                  memcpy(p_chunk + i * p_pool->node_size, &p_node, sizeof(p_node));                  memcpy((char *)p_chunk + i * p_pool->node_size, &p_node, sizeof(p_node));
102          }          }
103    
104          p_pool->p_chunks[p_pool->chunk_count] = p_chunk;          p_pool->p_chunks[p_pool->chunk_count] = p_chunk;
# Line 175  int memory_pool_check_node(MEMORY_POOL * Line 171  int memory_pool_check_node(MEMORY_POOL *
171    
172          for (i = 0; i < p_pool->chunk_count; i++)          for (i = 0; i < p_pool->chunk_count; i++)
173          {          {
174                  if (p_node >= p_pool->p_chunks[i] && p_node < p_pool->p_chunks[i] + chunk_size)                  if (p_node >= p_pool->p_chunks[i] && (char *)p_node < (char *)(p_pool->p_chunks[i]) + chunk_size)
175                  {                  {
176                          if ((size_t)(p_node - p_pool->p_chunks[i]) % p_pool->node_size == 0)                          if ((size_t)((char *)p_node - (char *)(p_pool->p_chunks[i])) % p_pool->node_size == 0)
177                          {                          {
178                                  return 0; // OK                                  return 0; // OK
179                          }                          }
180                          else                          else
181                          {                          {
182                                  log_error("Address of node (%p) is not aligned with border of chunk %d [%p, %p)\n",                                  log_error("Address of node (%p) is not aligned with border of chunk %d [%p, %p)\n",
183                                                    i, p_node >= p_pool->p_chunks[i], p_pool->p_chunks[i] + chunk_size);                                                    i, p_node >= p_pool->p_chunks[i], (char *)(p_pool->p_chunks[i]) + chunk_size);
184                                  return -3;                                  return -3;
185                          }                          }
186                  }                  }


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1