Mercurial > vim
comparison src/os_vms.c @ 16825:ce04ebdf26b8 v8.1.1414
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
commit https://github.com/vim/vim/commit/c799fe206e61f2e2c1231bc46cbe4bb354f3da69
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 28 23:08:19 2019 +0200
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Problem: Alloc() returning "char_u *" causes a lot of type casts.
Solution: Have it return "void *". (Mike Williams) Define ALLOC_ONE() to
check the simple allocations.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 28 May 2019 23:15:10 +0200 |
parents | fc58fee685e2 |
children | e3785af3ba0f |
comparison
equal
deleted
inserted
replaced
16824:1f6bb29738d2 | 16825:ce04ebdf26b8 |
---|---|
236 vul_item(&itmlst.string, LNM$C_NAMLENGTH, LNM$_STRING, buffer, &lengte); | 236 vul_item(&itmlst.string, LNM$C_NAMLENGTH, LNM$_STRING, buffer, &lengte); |
237 itmlst.nul = 0; | 237 itmlst.nul = 0; |
238 if (sys$trnlnm(&attrib, &d_file_dev, &d_lognam, NULL,&itmlst) == SS$_NORMAL) | 238 if (sys$trnlnm(&attrib, &d_file_dev, &d_lognam, NULL,&itmlst) == SS$_NORMAL) |
239 { | 239 { |
240 buffer[lengte] = '\0'; | 240 buffer[lengte] = '\0'; |
241 if (cp = (char_u *)alloc(lengte + 1)) | 241 if (cp = alloc(lengte + 1)) |
242 strcpy((char *)cp, buffer); | 242 strcpy((char *)cp, buffer); |
243 return(cp); | 243 return(cp); |
244 } | 244 } |
245 else if ((sbuf = getenv((char *)lognam))) | 245 else if ((sbuf = getenv((char *)lognam))) |
246 { | 246 { |
247 lengte = strlen(sbuf) + 1; | 247 lengte = strlen(sbuf) + 1; |
248 cp = (char_u *)alloc(lengte); | 248 cp = alloc(lengte); |
249 if (cp) | 249 if (cp) |
250 strcpy((char *)cp, sbuf); | 250 strcpy((char *)cp, sbuf); |
251 return cp; | 251 return cp; |
252 } | 252 } |
253 else | 253 else |
380 | 380 |
381 /* accept all DECC$K_FILE and DECC$K_DIRECTORY */ | 381 /* accept all DECC$K_FILE and DECC$K_DIRECTORY */ |
382 if (vms_match_num == 0) { | 382 if (vms_match_num == 0) { |
383 /* first time through, setup some things */ | 383 /* first time through, setup some things */ |
384 if (NULL == vms_fmatch) { | 384 if (NULL == vms_fmatch) { |
385 vms_fmatch = (char_u **)alloc(EXPL_ALLOC_INC * sizeof(char *)); | 385 vms_fmatch = ALLOC_MULT(char *, EXPL_ALLOC_INC); |
386 if (!vms_fmatch) | 386 if (!vms_fmatch) |
387 return 0; | 387 return 0; |
388 vms_match_alloced = EXPL_ALLOC_INC; | 388 vms_match_alloced = EXPL_ALLOC_INC; |
389 vms_match_free = EXPL_ALLOC_INC; | 389 vms_match_free = EXPL_ALLOC_INC; |
390 } | 390 } |
404 return 1; | 404 return 1; |
405 } | 405 } |
406 if (--vms_match_free == 0) { | 406 if (--vms_match_free == 0) { |
407 /* add more space to store matches */ | 407 /* add more space to store matches */ |
408 vms_match_alloced += EXPL_ALLOC_INC; | 408 vms_match_alloced += EXPL_ALLOC_INC; |
409 vms_fmatch = (char_u **)vim_realloc(vms_fmatch, | 409 vms_fmatch = vim_realloc(vms_fmatch, |
410 sizeof(char **) * vms_match_alloced); | 410 sizeof(char **) * vms_match_alloced); |
411 if (!vms_fmatch) | 411 if (!vms_fmatch) |
412 return 0; | 412 return 0; |
413 vms_match_free = EXPL_ALLOC_INC; | 413 vms_match_free = EXPL_ALLOC_INC; |
414 } | 414 } |
441 int files_alloced, files_free; | 441 int files_alloced, files_free; |
442 | 442 |
443 *num_file = 0; /* default: no files found */ | 443 *num_file = 0; /* default: no files found */ |
444 files_alloced = EXPL_ALLOC_INC; | 444 files_alloced = EXPL_ALLOC_INC; |
445 files_free = EXPL_ALLOC_INC; | 445 files_free = EXPL_ALLOC_INC; |
446 *file = (char_u **) alloc(sizeof(char_u **) * files_alloced); | 446 *file = ALLOC_MULT(char_u **, files_alloced); |
447 if (*file == NULL) | 447 if (*file == NULL) |
448 { | 448 { |
449 *num_file = 0; | 449 *num_file = 0; |
450 return FAIL; | 450 return FAIL; |
451 } | 451 } |
488 | 488 |
489 /* allocate memory for pointers */ | 489 /* allocate memory for pointers */ |
490 if (--files_free < 1) | 490 if (--files_free < 1) |
491 { | 491 { |
492 files_alloced += EXPL_ALLOC_INC; | 492 files_alloced += EXPL_ALLOC_INC; |
493 *file = (char_u **)vim_realloc(*file, | 493 *file = vim_realloc(*file, sizeof(char_u **) * files_alloced); |
494 sizeof(char_u **) * files_alloced); | |
495 if (*file == NULL) | 494 if (*file == NULL) |
496 { | 495 { |
497 *file = (char_u **)""; | 496 *file = (char_u **)""; |
498 *num_file = 0; | 497 *num_file = 0; |
499 return(FAIL); | 498 return(FAIL); |
647 /* get a big-enough buffer */ | 646 /* get a big-enough buffer */ |
648 len = strlen(instring) + 1; | 647 len = strlen(instring) + 1; |
649 if (len > buflen) | 648 if (len > buflen) |
650 { | 649 { |
651 buflen = len + 128; | 650 buflen = len + 128; |
652 if (buf) | 651 buf = vim_realloc(buf, buflen * sizeof(char)); |
653 buf = (char *)vim_realloc(buf, buflen); | |
654 else | |
655 buf = (char *)alloc(buflen * sizeof(char)); | |
656 } | 652 } |
657 | 653 |
658 #ifdef DEBUG | 654 #ifdef DEBUG |
659 char *tmpbuf = NULL; | 655 char *tmpbuf = NULL; |
660 tmpbuf = (char *)alloc(buflen * sizeof(char)); | 656 tmpbuf = ALLOC_MULT(char, buflen); |
661 strcpy(tmpbuf, instring); | 657 strcpy(tmpbuf, instring); |
662 #endif | 658 #endif |
663 | 659 |
664 Fspec_Rms = buf; /* for decc$to_vms */ | 660 Fspec_Rms = buf; /* for decc$to_vms */ |
665 | 661 |