Răsfoiți Sursa

fixbug: memmov

ithewei 5 ani în urmă
părinte
comite
e143d133b1
2 a modificat fișierele cu 8 adăugiri și 8 ștergeri
  1. 4 4
      base/array.h
  2. 4 4
      base/queue.h

+ 4 - 4
base/array.h

@@ -58,7 +58,7 @@ static inline type* atype##_front(atype* p) {\
 }\
 \
 static inline type* atype##_back(atype* p) {\
-    return p->size == 0 ? NULL : p->ptr+p->size-1;\
+    return p->size == 0 ? NULL : p->ptr + p->size - 1;\
 }\
 \
 static inline void atype##_init(atype* p, int maxsize) {\
@@ -84,7 +84,7 @@ static inline void atype##_resize(atype* p, int maxsize) {\
 }\
 \
 static inline void atype##_double_resize(atype* p) {\
-    atype##_resize(p, p->maxsize*2);\
+    atype##_resize(p, p->maxsize * 2);\
 }\
 \
 static inline void atype##_push_back(atype* p, type* elem) {\
@@ -109,7 +109,7 @@ static inline void atype##_add(atype* p, type* elem, int pos) {\
         atype##_double_resize(p);\
     }\
     if (pos < p->size) {\
-        memmove(p->ptr + pos+1, p->ptr + pos, sizeof(type)*(p->size-pos));\
+        memmove(p->ptr + pos+1, p->ptr + pos, sizeof(type) * (p->size - pos));\
     }\
     p->ptr[pos] = *elem;\
     p->size++;\
@@ -122,7 +122,7 @@ static inline void atype##_del(atype* p, int pos) {\
     assert(pos >= 0 && pos < p->size);\
     p->size--;\
     if (pos < p->size) {\
-        memmove(p->ptr + pos, p->ptr + pos+1, sizeof(type)*(p->size-pos));\
+        memmove(p->ptr + pos, p->ptr + pos+1, sizeof(type) * (p->size - pos));\
     }\
 }\
 \

+ 4 - 4
base/queue.h

@@ -49,7 +49,7 @@ static inline type* qtype##_front(qtype* p) {\
 }\
 \
 static inline type* qtype##_back(qtype* p) {\
-    return p->size == 0 ? NULL : p->ptr + p->_offset + p->size-1;\
+    return p->size == 0 ? NULL : p->ptr + p->_offset + p->size - 1;\
 }\
 \
 static inline void qtype##_init(qtype* p, int maxsize) {\
@@ -72,12 +72,12 @@ static inline void qtype##_cleanup(qtype* p) {\
 \
 static inline void qtype##_resize(qtype* p, int maxsize) {\
     if (maxsize == 0) maxsize = QUEUE_INIT_SIZE;\
-    p->ptr = (type*)safe_realloc(p->ptr, sizeof(type)*maxsize, sizeof(type)*p->maxsize);\
+    p->ptr = (type*)safe_realloc(p->ptr, sizeof(type) * maxsize, sizeof(type) * p->maxsize);\
     p->maxsize = maxsize;\
 }\
 \
 static inline void qtype##_double_resize(qtype* p) {\
-    qtype##_resize(p, p->maxsize*2);\
+    qtype##_resize(p, p->maxsize * 2);\
 }\
 \
 static inline void qtype##_push_back(qtype* p, type* elem) {\
@@ -85,7 +85,7 @@ static inline void qtype##_push_back(qtype* p, type* elem) {\
         qtype##_double_resize(p);\
     }\
     else if (p->_offset + p->size == p->maxsize) {\
-        memmove(p->ptr, p->ptr + p->_offset, p->size);\
+        memmove(p->ptr, p->ptr + p->_offset, sizeof(type) * p->size);\
         p->_offset = 0;\
     }\
     p->ptr[p->_offset + p->size] = *elem;\