From 2bedf5e8393f78f7d905262ddd438fb564ef7f0e Mon Sep 17 00:00:00 2001 From: "HuYingzhuo(hugo/hyzboy)" Date: Thu, 13 Jul 2023 14:29:26 +0800 Subject: [PATCH] fixed a bug in List<>, and it doesn't check count after realloc --- inc/hgl/type/List.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/inc/hgl/type/List.cpp b/inc/hgl/type/List.cpp index 346d987..fd3d5b5 100644 --- a/inc/hgl/type/List.cpp +++ b/inc/hgl/type/List.cpp @@ -87,15 +87,15 @@ namespace hgl return items; } - else + else if(count+1>alloc_count) { alloc_count=power_to_2(count+1); items=(T *)hgl_align_realloc(items,alloc_count); - - ++count; - return(items+(count-1)); } + + ++count; + return(items+(count-1)); } /** @@ -112,7 +112,7 @@ namespace hgl alloc_count=1; items=hgl_align_malloc(1); } - else + else if(count+1>alloc_count) { alloc_count=power_to_2(count+1); @@ -141,7 +141,7 @@ namespace hgl alloc_count=power_to_2(n); items=hgl_align_malloc(alloc_count); } - else + else if(count+n>alloc_count) { alloc_count=power_to_2(count+n); @@ -177,7 +177,7 @@ namespace hgl items=hgl_align_malloc(alloc_count); } - else + else if(count+n>alloc_count) { alloc_count=power_to_2(count+n); @@ -401,7 +401,7 @@ namespace hgl items=hgl_align_malloc(alloc_count); } - else + else if(count+1>alloc_count) { alloc_count=power_to_2(count+1);