MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / insert_pointer_name

Function insert_pointer_name

extra/replace.c:250–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248}
249
250static int insert_pointer_name(reg1 POINTER_ARRAY *pa,char * name)
251{
252 uint i,length,old_count;
253 uchar *new_pos;
254 const char **new_array;
255 DBUG_ENTER("insert_pointer_name");
256
257 if (! pa->typelib.count)
258 {
259 if (!(pa->typelib.type_names=(const char **)
260 my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
261 (sizeof(char *)+sizeof(*pa->flag))*
262 (sizeof(char *)+sizeof(*pa->flag))),MYF(MY_WME))))
263 DBUG_RETURN(-1);
264 if (!(pa->str= (uchar*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD),
265 MYF(MY_WME))))
266 {
267 my_free(pa->typelib.type_names);
268 DBUG_RETURN (-1);
269 }
270 pa->max_count=(PC_MALLOC-MALLOC_OVERHEAD)/(sizeof(uchar*)+
271 sizeof(*pa->flag));
272 pa->flag= (uint8*) (pa->typelib.type_names+pa->max_count);
273 pa->length=0;
274 pa->max_length=PS_MALLOC-MALLOC_OVERHEAD;
275 pa->array_allocs=1;
276 }
277 length=(uint) strlen(name)+1;
278 if (pa->length+length >= pa->max_length)
279 {
280 pa->max_length=(pa->length+length+MALLOC_OVERHEAD+PS_MALLOC-1)/PS_MALLOC;
281 pa->max_length=pa->max_length*PS_MALLOC-MALLOC_OVERHEAD;
282 if (!(new_pos= (uchar*) my_realloc((uchar*) pa->str,
283 (uint) pa->max_length,
284 MYF(MY_WME))))
285 DBUG_RETURN(1);
286 if (new_pos != pa->str)
287 {
288 my_ptrdiff_t diff=PTR_BYTE_DIFF(new_pos,pa->str);
289 for (i=0 ; i < pa->typelib.count ; i++)
290 pa->typelib.type_names[i]= ADD_TO_PTR(pa->typelib.type_names[i],diff,
291 char*);
292 pa->str=new_pos;
293 }
294 }
295 if (pa->typelib.count >= pa->max_count-1)
296 {
297 int len;
298 pa->array_allocs++;
299 len=(PC_MALLOC*pa->array_allocs - MALLOC_OVERHEAD);
300 if (!(new_array=(const char **) my_realloc((uchar*) pa->typelib.type_names,
301 (uint) len/
302 (sizeof(uchar*)+sizeof(*pa->flag))*
303 (sizeof(uchar*)+sizeof(*pa->flag)),
304 MYF(MY_WME))))
305 DBUG_RETURN(1);
306 pa->typelib.type_names=new_array;
307 old_count=pa->max_count;

Callers 1

get_replace_stringsFunction · 0.85

Calls 4

my_mallocFunction · 0.85
my_freeFunction · 0.85
my_reallocFunction · 0.85
strmovFunction · 0.85

Tested by

no test coverage detected