• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

BASIC compiler/interpreter for PIC32MX/MZ-80K


Commit MetaInfo

Révision2526d3441b908fe0e1ee3013aef738eca529c2d6 (tree)
l'heure2019-02-18 09:04:42
AuteurKatsumi <kmorimatsu@sour...>
CommiterKatsumi

Message de Log

Avoid possible invasion of allocated memory area.

Change Summary

Modification

--- a/mips/megalopa/memory.c
+++ b/mips/megalopa/memory.c
@@ -110,8 +110,6 @@ void* _alloc_memory_main(int size, int var_num){
110110 while(1){
111111 // Try the block previously deleted, not for temporary block.
112112 // This is for fast allocation of memory for class object.
113- // Note that the temporary areas can be invaded for following purpose
114- // because these are temporary ones.
115113 if (var_num<26 || ALLOC_VAR_NUM<=var_num) {
116114 candidate=0;
117115 while(g_deleted_num){
@@ -136,7 +134,29 @@ void* _alloc_memory_main(int size, int var_num){
136134 candidate=g_var_pointer[i]+g_var_size[i];
137135 }
138136 }
139- if (candidate+size<=g_max_mem) break;
137+ if (candidate+size<=g_max_mem) {
138+ // Check after deleted block
139+ j=candidate;
140+ for(i=0;i<g_deleted_num;i++){
141+ if (j<g_deleted_pointer[i]+g_deleted_size[i]) {
142+ j=g_deleted_pointer[i]+g_deleted_size[i];
143+ }
144+ }
145+ if (j+size<=g_max_mem) {
146+ // Candidate block found after previously deleted blokcs
147+ candidate=j;
148+ break;
149+ } else {
150+ // Candidate is before previously deleted blocks,
151+ // and there is no candidate block after previously deleted blocks.
152+ // Therefore, use the current candidate, which may invade previously
153+ // deleted blocks. Therefore, erase the previously deleted blocks list.
154+ g_deleted_num=0;
155+ break;
156+ }
157+ }
158+ // Peviously deleted blocks cannot be used any more
159+ g_deleted_num=0;
140160 // Check between blocks
141161 // Note that there is at least one block with zero pointer and zero size (see above).
142162 for(i=0;i<ALLOC_BLOCK_NUM;i++){