comparison src/dmgrowbuf.c @ 1814:0b7062d874ef

Use dmMemset() instead of memset().
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 21 Jun 2018 17:22:32 +0300
parents 0801fd0e26cb
children ca9fe688ab6b
comparison
equal deleted inserted replaced
1813:cfe9807a1e64 1814:0b7062d874ef
20 DM_DBG("dmGrowBufInit(%p)\n", buf); 20 DM_DBG("dmGrowBufInit(%p)\n", buf);
21 21
22 if (buf == NULL) 22 if (buf == NULL)
23 return DMERR_NULLPTR; 23 return DMERR_NULLPTR;
24 24
25 memset(buf, 0, sizeof(DMGrowBuf)); 25 dmMemset(buf, 0, sizeof(DMGrowBuf));
26 26
27 return DMERR_OK; 27 return DMERR_OK;
28 } 28 }
29 29
30 30
66 66
67 if (buf->is_const) 67 if (buf->is_const)
68 return; 68 return;
69 69
70 dmFree(buf->data); 70 dmFree(buf->data);
71 memset(buf, 0, sizeof(DMGrowBuf)); 71 dmMemset(buf, 0, sizeof(DMGrowBuf));
72 } 72 }
73 } 73 }
74 74
75 75
76 DMGrowBuf * dmGrowBufCopy(DMGrowBuf *dst, const DMGrowBuf *src, const size_t enlarge) 76 DMGrowBuf * dmGrowBufCopy(DMGrowBuf *dst, const DMGrowBuf *src, const size_t enlarge)
88 88
89 // Allocate new memory for the data 89 // Allocate new memory for the data
90 if ((dst->data = dmMalloc(dst->size)) == NULL) 90 if ((dst->data = dmMalloc(dst->size)) == NULL)
91 { 91 {
92 // If that fails, clear the struct 92 // If that fails, clear the struct
93 memset(dst, 0, sizeof(DMGrowBuf)); 93 dmMemset(dst, 0, sizeof(DMGrowBuf));
94 return NULL; 94 return NULL;
95 } 95 }
96 96
97 // Copy data 97 // Copy data
98 memcpy(dst->data, src->data, src->size); 98 memcpy(dst->data, src->data, src->size);
99 if (enlarge > 0) 99 if (enlarge > 0)
100 memset(dst->data + src->size, 0, enlarge); 100 dmMemset(dst->data + src->size, 0, enlarge);
101 101
102 // And reset some struct information 102 // And reset some struct information
103 dst->is_const = FALSE; 103 dst->is_const = FALSE;
104 104
105 return dst; 105 return dst;
181 181
182 // Check if we need to clear the newly allocated area? 182 // Check if we need to clear the newly allocated area?
183 if (clear) 183 if (clear)
184 { 184 {
185 if (buf->backwards) 185 if (buf->backwards)
186 memset(buf->data, 0, clrsize); 186 dmMemset(buf->data, 0, clrsize);
187 else 187 else
188 memset(buf->data + buf->size, 0, clrsize); 188 dmMemset(buf->data + buf->size, 0, clrsize);
189 } 189 }
190 190
191 buf->size = nsize; 191 buf->size = nsize;
192 192
193 return TRUE; 193 return TRUE;