/[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.8 by sysadm, Tue Nov 4 14:58:56 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     */
 /***************************************************************************  
  *                                                                         *  
  *   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.                                   *  
  *                                                                         *  
  ***************************************************************************/  
8    
9  #include "log.h"  #include "log.h"
10  #include "memory_pool.h"  #include "memory_pool.h"
# Line 98  inline static void *memory_pool_add_chun Line 90  inline static void *memory_pool_add_chun
90          }          }
91    
92          p_node = p_pool->p_free;          p_node = p_pool->p_free;
93          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));
94          for (i = 0; i < p_pool->node_count_per_chunk - 1; i++)          for (i = 0; i < p_pool->node_count_per_chunk - 1; i++)
95          {          {
96                  p_node = p_chunk + (i + 1) * p_pool->node_size;                  p_node = (char *)p_chunk + (i + 1) * p_pool->node_size;
97                  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));
98          }          }
99    
100          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 167  int memory_pool_check_node(MEMORY_POOL *
167    
168          for (i = 0; i < p_pool->chunk_count; i++)          for (i = 0; i < p_pool->chunk_count; i++)
169          {          {
170                  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)
171                  {                  {
172                          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)
173                          {                          {
174                                  return 0; // OK                                  return 0; // OK
175                          }                          }
176                          else                          else
177                          {                          {
178                                  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",
179                                                    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);
180                                  return -3;                                  return -3;
181                          }                          }
182                  }                  }


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

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