summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-01-26 10:40:27 -0800
committerKaz Kylheku <kaz@kylheku.com>2020-01-26 10:40:27 -0800
commitdb3a993df7b97259468b80e62cb27ce56e2ed051 (patch)
treea75f99a81ae142e08e943c98eefa0250dc971cfa
parente4ef3f03d9f01f92482fa9ac7ec18f54a6847c65 (diff)
downloadc-snippets-db3a993df7b97259468b80e62cb27ce56e2ed051.tar.gz
c-snippets-db3a993df7b97259468b80e62cb27ce56e2ed051.tar.bz2
c-snippets-db3a993df7b97259468b80e62cb27ce56e2ed051.zip
Fix signed/unsigned comparison warnings.
These show up when compiled with -Wall -W options of gcc. Note: the code captures the return values of strlen and strspn in signed variables of type long on purpose, so that some of the arithmetic and comparisons are done sanely around zero. We don't expect the values to go anywhere near 32 or 64 bit wraparound limits; the casts will never produce a negative value in any reasonable use of the program. In this patch we make that more consistent: a couple of lengths were captured in size_t variables; now they are long. One remaining signed/unsigned comparison warning is squelched with a cast.
-rw-r--r--autotab.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/autotab.c b/autotab.c
index 6ddc384..0c27bfb 100644
--- a/autotab.c
+++ b/autotab.c
@@ -419,7 +419,7 @@ static long compute_alignment_score(line_t *lines, int shiftwidth)
lines = next, next = next ? next->next : 0, lineno0 = lineno1++)
{
char *str0 = lines->str;
- size_t len0 = strlen(str0);
+ long len0 = strlen(str0);
long tnd0 = strspn(str0, LETAB); /* leading space generated by tabs */
long ind0 = strspn(str0, ANYSP); /* indentation */
long int0 = strcspn(str0, INTAB); /* position of first inner tab */
@@ -440,7 +440,7 @@ static long compute_alignment_score(line_t *lines, int shiftwidth)
for (; next && lineno1 - lineno0 <= 4; next = next->next, lineno1++)
{
char *str1 = next->str;
- size_t len1 = strlen(str1);
+ long len1 = strlen(str1);
long tnd1 = strspn(str1, LETAB);
long ind1 = strspn(str1, ANYSP);
long int1 = strcspn(str1, INTAB);
@@ -642,7 +642,7 @@ static int determine_shiftwidth(line_t *lines_in, int tabsize, int munged)
/* Indentation out of column zero tabulated separately.
Consider only if second line goes beyond previous line,
or if the indentation does not suspiciously look like alignment. */
- if (strlen(str0) < ind1 ||
+ if (strlen(str0) < (size_t) ind1 ||
!(strchr(ANYSP, str0[ind1 - 1]) != 0 &&
strchr(ANYSP, str0[ind1]) == 0))
zerocol_hist[move]++;