Mercurial > vim
comparison src/if_cscope.c @ 16764:ef00b6bc186b v8.1.1384
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
commit https://github.com/vim/vim/commit/964b3746b9c81e65887e2ac9a335f181db2bb592
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri May 24 18:54:09 2019 +0200
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Problem: Using "int" for alloc() often results in compiler warnings.
Solution: Use "size_t" and remove type casts. Remove alloc_check(), Vim
only works with 32 bit ints anyway.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 24 May 2019 19:00:07 +0200 |
parents | b52ea9c5f1db |
children | ce04ebdf26b8 |
comparison
equal
deleted
inserted
replaced
16763:fccf84413b53 | 16764:ef00b6bc186b |
---|---|
464 | 464 |
465 static void | 465 static void |
466 cs_stat_emsg(char *fname) | 466 cs_stat_emsg(char *fname) |
467 { | 467 { |
468 char *stat_emsg = _("E563: stat(%s) error: %d"); | 468 char *stat_emsg = _("E563: stat(%s) error: %d"); |
469 char *buf = (char *)alloc((unsigned)strlen(stat_emsg) + MAXPATHL + 10); | 469 char *buf = (char *)alloc(strlen(stat_emsg) + MAXPATHL + 10); |
470 | 470 |
471 if (buf != NULL) | 471 if (buf != NULL) |
472 { | 472 { |
473 (void)sprintf(buf, stat_emsg, fname, errno); | 473 (void)sprintf(buf, stat_emsg, fname, errno); |
474 (void)emsg(buf); | 474 (void)emsg(buf); |
541 } | 541 } |
542 | 542 |
543 /* if filename is a directory, append the cscope database name to it */ | 543 /* if filename is a directory, append the cscope database name to it */ |
544 if (S_ISDIR(statbuf.st_mode)) | 544 if (S_ISDIR(statbuf.st_mode)) |
545 { | 545 { |
546 fname2 = (char *)alloc((unsigned)(strlen(CSCOPE_DBFILE) + strlen(fname) + 2)); | 546 fname2 = (char *)alloc(strlen(CSCOPE_DBFILE) + strlen(fname) + 2); |
547 if (fname2 == NULL) | 547 if (fname2 == NULL) |
548 goto add_err; | 548 goto add_err; |
549 | 549 |
550 while (fname[strlen(fname)-1] == '/' | 550 while (fname[strlen(fname)-1] == '/' |
551 #ifdef MSWIN | 551 #ifdef MSWIN |
767 pat = pattern; | 767 pat = pattern; |
768 if (search != 4 && search != 6) | 768 if (search != 4 && search != 6) |
769 while VIM_ISWHITE(*pat) | 769 while VIM_ISWHITE(*pat) |
770 ++pat; | 770 ++pat; |
771 | 771 |
772 if ((cmd = (char *)alloc((unsigned)(strlen(pat) + 2))) == NULL) | 772 if ((cmd = (char *)alloc(strlen(pat) + 2)) == NULL) |
773 return NULL; | 773 return NULL; |
774 | 774 |
775 (void)sprintf(cmd, "%d%s", search, pat); | 775 (void)sprintf(cmd, "%d%s", search, pat); |
776 | 776 |
777 return cmd; | 777 return cmd; |
1119 qfpos++; | 1119 qfpos++; |
1120 /* next symbol must be + or - */ | 1120 /* next symbol must be + or - */ |
1121 if (strchr(CSQF_FLAGS, *qfpos) == NULL) | 1121 if (strchr(CSQF_FLAGS, *qfpos) == NULL) |
1122 { | 1122 { |
1123 char *nf = _("E469: invalid cscopequickfix flag %c for %c"); | 1123 char *nf = _("E469: invalid cscopequickfix flag %c for %c"); |
1124 char *buf = (char *)alloc((unsigned)strlen(nf)); | 1124 char *buf = (char *)alloc(strlen(nf)); |
1125 | 1125 |
1126 /* strlen will be enough because we use chars */ | 1126 /* strlen will be enough because we use chars */ |
1127 if (buf != NULL) | 1127 if (buf != NULL) |
1128 { | 1128 { |
1129 sprintf(buf, nf, *qfpos, *(qfpos-1)); | 1129 sprintf(buf, nf, *qfpos, *(qfpos-1)); |
1190 { | 1190 { |
1191 vim_free(nummatches); | 1191 vim_free(nummatches); |
1192 return FALSE; | 1192 return FALSE; |
1193 } | 1193 } |
1194 | 1194 |
1195 buf = (char *)alloc((unsigned)(strlen(opt) + strlen(pat) + strlen(nf))); | 1195 buf = (char *)alloc(strlen(opt) + strlen(pat) + strlen(nf)); |
1196 if (buf == NULL) | 1196 if (buf == NULL) |
1197 (void)emsg(nf); | 1197 (void)emsg(nf); |
1198 else | 1198 else |
1199 { | 1199 { |
1200 sprintf(buf, nf, opt, pat); | 1200 sprintf(buf, nf, opt, pat); |
1448 return -1; | 1448 return -1; |
1449 for (j = csinfo_size/2; j < csinfo_size; j++) | 1449 for (j = csinfo_size/2; j < csinfo_size; j++) |
1450 clear_csinfo(j); | 1450 clear_csinfo(j); |
1451 } | 1451 } |
1452 | 1452 |
1453 if ((csinfo[i].fname = (char *)alloc((unsigned)strlen(fname)+1)) == NULL) | 1453 if ((csinfo[i].fname = (char *)alloc(strlen(fname)+1)) == NULL) |
1454 return -1; | 1454 return -1; |
1455 | 1455 |
1456 (void)strcpy(csinfo[i].fname, (const char *)fname); | 1456 (void)strcpy(csinfo[i].fname, (const char *)fname); |
1457 | 1457 |
1458 if (ppath != NULL) | 1458 if (ppath != NULL) |
1459 { | 1459 { |
1460 if ((csinfo[i].ppath = (char *)alloc((unsigned)strlen(ppath) + 1)) == NULL) | 1460 if ((csinfo[i].ppath = (char *)alloc(strlen(ppath) + 1)) == NULL) |
1461 { | 1461 { |
1462 VIM_CLEAR(csinfo[i].fname); | 1462 VIM_CLEAR(csinfo[i].fname); |
1463 return -1; | 1463 return -1; |
1464 } | 1464 } |
1465 (void)strcpy(csinfo[i].ppath, (const char *)ppath); | 1465 (void)strcpy(csinfo[i].ppath, (const char *)ppath); |
1466 } else | 1466 } else |
1467 csinfo[i].ppath = NULL; | 1467 csinfo[i].ppath = NULL; |
1468 | 1468 |
1469 if (flags != NULL) | 1469 if (flags != NULL) |
1470 { | 1470 { |
1471 if ((csinfo[i].flags = (char *)alloc((unsigned)strlen(flags) + 1)) == NULL) | 1471 if ((csinfo[i].flags = (char *)alloc(strlen(flags) + 1)) == NULL) |
1472 { | 1472 { |
1473 VIM_CLEAR(csinfo[i].fname); | 1473 VIM_CLEAR(csinfo[i].fname); |
1474 VIM_CLEAR(csinfo[i].ppath); | 1474 VIM_CLEAR(csinfo[i].ppath); |
1475 return -1; | 1475 return -1; |
1476 } | 1476 } |
1818 { | 1818 { |
1819 if ((fullname = cs_parse_results(i, buf, CSREAD_BUFSIZE, &cntx, | 1819 if ((fullname = cs_parse_results(i, buf, CSREAD_BUFSIZE, &cntx, |
1820 &slno, &search)) == NULL) | 1820 &slno, &search)) == NULL) |
1821 continue; | 1821 continue; |
1822 | 1822 |
1823 context = (char *)alloc((unsigned)strlen(cntx)+5); | 1823 context = (char *)alloc(strlen(cntx)+5); |
1824 if (context == NULL) | 1824 if (context == NULL) |
1825 continue; | 1825 continue; |
1826 | 1826 |
1827 if (strcmp(cntx, "<global>")==0) | 1827 if (strcmp(cntx, "<global>")==0) |
1828 strcpy(context, "<<global>>"); | 1828 strcpy(context, "<<global>>"); |
1973 char *cstag_msg = _("Cscope tag: %s"); | 1973 char *cstag_msg = _("Cscope tag: %s"); |
1974 char *csfmt_str = "%4d %6s "; | 1974 char *csfmt_str = "%4d %6s "; |
1975 | 1975 |
1976 assert(num_matches > 0); | 1976 assert(num_matches > 0); |
1977 | 1977 |
1978 if ((tbuf = (char *)alloc((unsigned)strlen(matches[0]) + 1)) == NULL) | 1978 if ((tbuf = (char *)alloc(strlen(matches[0]) + 1)) == NULL) |
1979 return; | 1979 return; |
1980 | 1980 |
1981 strcpy(tbuf, matches[0]); | 1981 strcpy(tbuf, matches[0]); |
1982 ptag = strtok(tbuf, "\t"); | 1982 ptag = strtok(tbuf, "\t"); |
1983 if (ptag == NULL) | 1983 if (ptag == NULL) |
2008 | 2008 |
2009 /* if we really wanted to, we could avoid this malloc and strcpy | 2009 /* if we really wanted to, we could avoid this malloc and strcpy |
2010 * by parsing matches[i] on the fly and placing stuff into buf | 2010 * by parsing matches[i] on the fly and placing stuff into buf |
2011 * directly, but that's too much of a hassle | 2011 * directly, but that's too much of a hassle |
2012 */ | 2012 */ |
2013 if ((tbuf = (char *)alloc((unsigned)strlen(matches[idx]) + 1)) == NULL) | 2013 if ((tbuf = (char *)alloc(strlen(matches[idx]) + 1)) == NULL) |
2014 continue; | 2014 continue; |
2015 (void)strcpy(tbuf, matches[idx]); | 2015 (void)strcpy(tbuf, matches[idx]); |
2016 | 2016 |
2017 if (strtok(tbuf, (const char *)"\t") == NULL | 2017 if (strtok(tbuf, (const char *)"\t") == NULL |
2018 || (fname = strtok(NULL, (const char *)"\t")) == NULL | 2018 || (fname = strtok(NULL, (const char *)"\t")) == NULL |