Mercurial > vim
comparison src/undo.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 | 695d9ef00b03 |
children | d5e1e09a829f |
comparison
equal
deleted
inserted
replaced
16824:1f6bb29738d2 | 16825:ce04ebdf26b8 |
---|---|
466 { | 466 { |
467 /* | 467 /* |
468 * Make a new header entry. Do this first so that we don't mess | 468 * Make a new header entry. Do this first so that we don't mess |
469 * up the undo info when out of memory. | 469 * up the undo info when out of memory. |
470 */ | 470 */ |
471 uhp = (u_header_T *)U_ALLOC_LINE(sizeof(u_header_T)); | 471 uhp = U_ALLOC_LINE(sizeof(u_header_T)); |
472 if (uhp == NULL) | 472 if (uhp == NULL) |
473 goto nomem; | 473 goto nomem; |
474 #ifdef U_DEBUG | 474 #ifdef U_DEBUG |
475 uhp->uh_magic = UH_MAGIC; | 475 uhp->uh_magic = UH_MAGIC; |
476 #endif | 476 #endif |
657 #endif | 657 #endif |
658 | 658 |
659 /* | 659 /* |
660 * add lines in front of entry list | 660 * add lines in front of entry list |
661 */ | 661 */ |
662 uep = (u_entry_T *)U_ALLOC_LINE(sizeof(u_entry_T)); | 662 uep = U_ALLOC_LINE(sizeof(u_entry_T)); |
663 if (uep == NULL) | 663 if (uep == NULL) |
664 goto nomem; | 664 goto nomem; |
665 vim_memset(uep, 0, sizeof(u_entry_T)); | 665 vim_memset(uep, 0, sizeof(u_entry_T)); |
666 #ifdef U_DEBUG | 666 #ifdef U_DEBUG |
667 uep->ue_magic = UE_MAGIC; | 667 uep->ue_magic = UE_MAGIC; |
683 curbuf->b_u_newhead->uh_getbot_entry = uep; | 683 curbuf->b_u_newhead->uh_getbot_entry = uep; |
684 } | 684 } |
685 | 685 |
686 if (size > 0) | 686 if (size > 0) |
687 { | 687 { |
688 if ((uep->ue_array = (undoline_T *)U_ALLOC_LINE( | 688 if ((uep->ue_array = U_ALLOC_LINE(sizeof(undoline_T) * size)) == NULL) |
689 sizeof(undoline_T) * size)) == NULL) | |
690 { | 689 { |
691 u_freeentry(uep, 0L); | 690 u_freeentry(uep, 0L); |
692 goto nomem; | 691 goto nomem; |
693 } | 692 } |
694 for (i = 0, lnum = top + 1; i < size; ++i) | 693 for (i = 0, lnum = top + 1; i < size; ++i) |
1284 int i; | 1283 int i; |
1285 u_entry_T *uep, *last_uep; | 1284 u_entry_T *uep, *last_uep; |
1286 int c; | 1285 int c; |
1287 int error; | 1286 int error; |
1288 | 1287 |
1289 uhp = (u_header_T *)U_ALLOC_LINE(sizeof(u_header_T)); | 1288 uhp = U_ALLOC_LINE(sizeof(u_header_T)); |
1290 if (uhp == NULL) | 1289 if (uhp == NULL) |
1291 return NULL; | 1290 return NULL; |
1292 vim_memset(uhp, 0, sizeof(u_header_T)); | 1291 vim_memset(uhp, 0, sizeof(u_header_T)); |
1293 #ifdef U_DEBUG | 1292 #ifdef U_DEBUG |
1294 uhp->uh_magic = UH_MAGIC; | 1293 uhp->uh_magic = UH_MAGIC; |
1395 u_entry_T *uep; | 1394 u_entry_T *uep; |
1396 undoline_T *array = NULL; | 1395 undoline_T *array = NULL; |
1397 char_u *line; | 1396 char_u *line; |
1398 int line_len; | 1397 int line_len; |
1399 | 1398 |
1400 uep = (u_entry_T *)U_ALLOC_LINE(sizeof(u_entry_T)); | 1399 uep = U_ALLOC_LINE(sizeof(u_entry_T)); |
1401 if (uep == NULL) | 1400 if (uep == NULL) |
1402 return NULL; | 1401 return NULL; |
1403 vim_memset(uep, 0, sizeof(u_entry_T)); | 1402 vim_memset(uep, 0, sizeof(u_entry_T)); |
1404 #ifdef U_DEBUG | 1403 #ifdef U_DEBUG |
1405 uep->ue_magic = UE_MAGIC; | 1404 uep->ue_magic = UE_MAGIC; |
1409 uep->ue_lcount = undo_read_4c(bi); | 1408 uep->ue_lcount = undo_read_4c(bi); |
1410 uep->ue_size = undo_read_4c(bi); | 1409 uep->ue_size = undo_read_4c(bi); |
1411 if (uep->ue_size > 0) | 1410 if (uep->ue_size > 0) |
1412 { | 1411 { |
1413 if (uep->ue_size < LONG_MAX / (int)sizeof(char_u *)) | 1412 if (uep->ue_size < LONG_MAX / (int)sizeof(char_u *)) |
1414 array = (undoline_T *)U_ALLOC_LINE(sizeof(undoline_T) * uep->ue_size); | 1413 array = U_ALLOC_LINE(sizeof(undoline_T) * uep->ue_size); |
1415 if (array == NULL) | 1414 if (array == NULL) |
1416 { | 1415 { |
1417 *error = TRUE; | 1416 *error = TRUE; |
1418 return uep; | 1417 return uep; |
1419 } | 1418 } |
1979 * sequence numbers of the headers. | 1978 * sequence numbers of the headers. |
1980 * When there are no headers uhp_table is NULL. */ | 1979 * When there are no headers uhp_table is NULL. */ |
1981 if (num_head > 0) | 1980 if (num_head > 0) |
1982 { | 1981 { |
1983 if (num_head < LONG_MAX / (long)sizeof(u_header_T *)) | 1982 if (num_head < LONG_MAX / (long)sizeof(u_header_T *)) |
1984 uhp_table = (u_header_T **)U_ALLOC_LINE( | 1983 uhp_table = U_ALLOC_LINE(num_head * sizeof(u_header_T *)); |
1985 num_head * sizeof(u_header_T *)); | |
1986 if (uhp_table == NULL) | 1984 if (uhp_table == NULL) |
1987 goto error; | 1985 goto error; |
1988 } | 1986 } |
1989 | 1987 |
1990 while ((c = undo_read_2c(&bi)) == UF_HEADER_MAGIC) | 1988 while ((c = undo_read_2c(&bi)) == UF_HEADER_MAGIC) |
2011 corruption_error("end marker", file_name); | 2009 corruption_error("end marker", file_name); |
2012 goto error; | 2010 goto error; |
2013 } | 2011 } |
2014 | 2012 |
2015 #ifdef U_DEBUG | 2013 #ifdef U_DEBUG |
2016 uhp_table_used = (int *)alloc_clear(sizeof(int) * num_head + 1); | 2014 uhp_table_used = alloc_clear(sizeof(int) * num_head + 1); |
2017 # define SET_FLAG(j) ++uhp_table_used[j] | 2015 # define SET_FLAG(j) ++uhp_table_used[j] |
2018 #else | 2016 #else |
2019 # define SET_FLAG(j) | 2017 # define SET_FLAG(j) |
2020 #endif | 2018 #endif |
2021 | 2019 |
2710 empty_buffer = FALSE; | 2708 empty_buffer = FALSE; |
2711 | 2709 |
2712 /* delete the lines between top and bot and save them in newarray */ | 2710 /* delete the lines between top and bot and save them in newarray */ |
2713 if (oldsize > 0) | 2711 if (oldsize > 0) |
2714 { | 2712 { |
2715 if ((newarray = (undoline_T *)U_ALLOC_LINE( | 2713 if ((newarray = U_ALLOC_LINE(sizeof(undoline_T) * oldsize)) == NULL) |
2716 sizeof(undoline_T) * oldsize)) == NULL) | |
2717 { | 2714 { |
2718 do_outofmem_msg((long_u)(sizeof(undoline_T) * oldsize)); | 2715 do_outofmem_msg((long_u)(sizeof(undoline_T) * oldsize)); |
2719 /* | 2716 /* |
2720 * We have messed up the entry list, repair is impossible. | 2717 * We have messed up the entry list, repair is impossible. |
2721 * we have to free the rest of the list. | 2718 * we have to free the rest of the list. |