Skip to content

Commit

Permalink
Pass unsigned char as int to vStringPut()
Browse files Browse the repository at this point in the history
`vStringPut()` is expected to be used mostly with values conforming to
the return value from `fgetc()` and alike, which is an `unsigned char`
as an `int`.

It works well for return values from `getcFromInputFile()` or iterating
over `readLineFromInputFile()`, but not over `char*`.

This commit should fix all calls, either:

* adding an `unsigned int` cast when appropriate;
* removing an incorrect `char` cast;
* removing a useless `int` cast that is more confusing than useful.
  • Loading branch information
b4n committed May 15, 2023
1 parent a7802b5 commit 913aefc
Show file tree
Hide file tree
Showing 49 changed files with 123 additions and 124 deletions.
2 changes: 1 addition & 1 deletion dsl/optscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -4184,7 +4184,7 @@ op__put_str (OptVM *vm, EsObject *name,
for (size_t i = 0; i < d; i++)
vStringPut (vstr, ' ');
if (c != 0)
vStringPut (vstr, (char)c);
vStringPut (vstr, (unsigned char)c);
}

ptrArrayDeleteLastInBatch (vm->ostack, 3);
Expand Down
2 changes: 1 addition & 1 deletion main/colprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void colprintLineAppendColumnVString (struct colprintLine *line, vString* column
void colprintLineAppendColumnChar (struct colprintLine *line, char column)
{
vString* vcol = vStringNew ();
vStringPut (vcol, column);
vStringPut (vcol, (unsigned char) column);
colprintLineAppendColumn (line, vcol);
}

Expand Down
2 changes: 1 addition & 1 deletion main/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ static size_t appendInputLine (int putc_func (char , void *), const char *const
static int vstring_putc (char c, void *data)
{
vString *str = data;
vStringPut (str, c);
vStringPut (str, (unsigned char) c);
return 1;
}

Expand Down
5 changes: 2 additions & 3 deletions main/field.c
Original file line number Diff line number Diff line change
Expand Up @@ -863,13 +863,12 @@ extern bool doesFieldHaveTabOrNewlineChar (fieldType type, const tagEntryInfo *
static const char* renderCompactInputLine (vString *b, const char *const line)
{
bool lineStarted = false;
const char *p;
int c;

/* Write everything up to, but not including, the newline.
*/
for (p = line, c = *p ; c != NEWLINE && c != '\0' ; c = *++p)
for (const char *p = line; *p != NEWLINE && *p != '\0'; ++p)
{
int c = (unsigned char) *p;
if (lineStarted || ! isspace (c)) /* ignore leading spaces */
{
lineStarted = true;
Expand Down
8 changes: 4 additions & 4 deletions main/fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ extern fmtElement *fmtNew (const char* fmtString)
{
if (literal == NULL)
literal = vStringNew ();
vStringPut (literal, cursor[i]);
vStringPut (literal, (unsigned char) cursor[i]);
}
else
{
Expand Down Expand Up @@ -304,7 +304,7 @@ extern fmtElement *fmtNew (const char* fmtString)
{
if (width == NULL)
width = vStringNew ();
vStringPut (width, cursor[i]);
vStringPut (width, (unsigned char) cursor[i]);
i++;

if (cursor [i] == '\0')
Expand All @@ -330,7 +330,7 @@ extern fmtElement *fmtNew (const char* fmtString)

i++;
for (; cursor[i] != '}'; i++)
vStringPut (field_name, cursor[i]);
vStringPut (field_name, (unsigned char) cursor[i]);

last = queueTagField (last, column_width, truncation,
NUL_FIELD_LETTER, vStringValue (field_name));
Expand All @@ -352,7 +352,7 @@ extern fmtElement *fmtNew (const char* fmtString)
if (literal == NULL)
literal = vStringNew ();

vStringPut (literal, cursor[i]);
vStringPut (literal, (unsigned char) cursor[i]);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion main/kind.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ extern void roleColprintAddRoles (struct colprintTable *table, struct kindContro

colprintLineAppendColumnCString (line, lang);

vStringPut (kind_l_and_n, k->letter);
vStringPut (kind_l_and_n, (unsigned char) k->letter);
vStringPut (kind_l_and_n, '/');
vStringCatS (kind_l_and_n, k->name);
colprintLineAppendColumnVString (line, kind_l_and_n);
Expand Down
8 changes: 4 additions & 4 deletions main/lregex.c
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ static vString* substitute (
}
}
else if (*p != '\n' && *p != '\r')
vStringPut (result, *p);
vStringPut (result, (unsigned char) *p);
}
return result;
}
Expand Down Expand Up @@ -2220,7 +2220,7 @@ static char *escapeRegexPattern (const char* pattern)
else if (c == '\\')
vStringCatS(p, "\\\\");
else
vStringPut(p, c);
vStringPut(p, (unsigned char) c);

pattern++;
}
Expand Down Expand Up @@ -2440,7 +2440,7 @@ static void addTagRegexOption (struct lregexControlBlock *lcb,
vString *tmp = vStringNew ();

/* Put '^' as prefix for the pattern */
vStringPut(tmp, *c);
vStringPut(tmp, (unsigned char) *c);
vStringPut(tmp, '^');
vStringCatS(tmp, c + 1);
regex_pat = vStringDeleteUnwrap(tmp);
Expand Down Expand Up @@ -2706,7 +2706,7 @@ static void printInputLine(FILE* vfp, const char *c, const off_t offset)
vString *v = vStringNew ();

for (; *c && (*c != '\n'); c++)
vStringPut(v, *c);
vStringPut(v, (unsigned char) *c);

if (vStringLength (v) == 0 && *c == '\n')
vStringCatS (v, "\\n");
Expand Down
10 changes: 5 additions & 5 deletions main/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ static void processExtraTagsOption (

longName = vStringNewOrClearWithAutoRelease (longName);

while ((c = *p++) != '\0')
while ((c = (unsigned char) *p++) != '\0')
{
switch (c)
{
Expand Down Expand Up @@ -1374,7 +1374,7 @@ static void processFieldsOption (
else if (*p != '+' && *p != '-')
resetFieldsOption (LANG_IGNORE, false);

while ((c = *p++) != '\0') switch (c)
while ((c = (unsigned char) *p++) != '\0') switch (c)
{
case '+':
if (inLongName)
Expand Down Expand Up @@ -2453,7 +2453,7 @@ static void processPseudoTags (const char *const option CTAGS_ATTR_UNUSED,
p++;
while (*p != '\0' && *p != '}')
{
vStringPut (str, *p);
vStringPut (str, (unsigned char) *p);
p++;
}
if (*p != '}')
Expand Down Expand Up @@ -3084,7 +3084,7 @@ static bool processLangSpecificFieldsOption (const char *const option,
error (WARNING, "Wrong per language field specification: %s", p);

longName = vStringNewOrClearWithAutoRelease (longName);
while ((c = *p++) != '\0')
while ((c = (unsigned char) *p++) != '\0')
{
switch (c)
{
Expand Down Expand Up @@ -3185,7 +3185,7 @@ static bool processLangSpecificExtraOption (const char *const option,
error (WARNING, "Wrong per language extra specification: %s", p);

longName = vStringNewOrClearWithAutoRelease (longName);
while ((c = *p++) != '\0')
while ((c = (unsigned char) *p++) != '\0')
{
switch (c)
{
Expand Down
26 changes: 13 additions & 13 deletions main/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ static vString* determineInterpreter (const char* const cmd)
for ( ; isspace ((int) *p) ; ++p)
; /* no-op */
for ( ; *p != '\0' && ! isspace ((int) *p) ; ++p)
vStringPut (interpreter, (int) *p);
vStringPut (interpreter, (unsigned char) *p);
} while (strcmp (vStringValue (interpreter), "env") == 0);
return interpreter;
}
Expand Down Expand Up @@ -823,7 +823,7 @@ static vString* determineEmacsModeAtFirstLine (const char* const line)
for ( ; isspace ((int) *p) ; ++p)
; /* no-op */
for ( ; *p != '\0' && isLanguageNameChar ((int) *p) ; ++p)
vStringPut (mode, (int) *p);
vStringPut (mode, (unsigned char) *p);

if ((strcmp(vStringValue (mode), "sh") == 0
|| strcmp(vStringValue (mode), "shell-script") == 0)
Expand All @@ -839,7 +839,7 @@ static vString* determineEmacsModeAtFirstLine (const char* const line)
goto out;

for ( ; p < end && isLanguageNameChar ((int) *p) ; ++p)
vStringPut (mode, (int) *p);
vStringPut (mode, (unsigned char) *p);

for ( ; isspace ((int) *p) ; ++p)
; /* no-op */
Expand Down Expand Up @@ -891,7 +891,7 @@ static vString* determineEmacsModeAtEOF (MIO* const fp)
for ( ; isspace ((int) *p) ; ++p)
; /* no-op */
for ( ; *p != '\0' && isLanguageNameChar ((int) *p) ; ++p)
vStringPut (mode, (int) *p);
vStringPut (mode, (unsigned char) *p);

is_shell_mode = ((strcasecmp (vStringValue (mode), "sh") == 0
|| strcasecmp (vStringValue (mode), "shell-script") == 0));
Expand Down Expand Up @@ -955,7 +955,7 @@ static vString* determineVimFileType (const char *const modeline)

p += strlen(filetype_prefix[i]);
for ( ; *p != '\0' && isalnum ((int) *p) ; ++p)
vStringPut (filetype, (int) *p);
vStringPut (filetype, (unsigned char) *p);
break;
}
return filetype;
Expand Down Expand Up @@ -2542,7 +2542,7 @@ static void processLangKindDefinition (

longName = vStringNewOrClearWithAutoRelease (longName);

while ((c = *p++) != '\0')
while ((c = (unsigned char) *p++) != '\0')
{
switch (c)
{
Expand Down Expand Up @@ -2605,28 +2605,28 @@ static char *extractDescriptionAndFlags(const char *input, const char **flags)
{
vString *vdesc = vStringNew();
bool escaped = false;
int c;

if (flags)
*flags = NULL;

while (*input != '\0')
while ((c = (unsigned char) *input) != '\0')
{
if (escaped)
{
vStringPut (vdesc, *input);
vStringPut (vdesc, c);
escaped = false;

}
else if (*input == '\\')
else if (c == '\\')
escaped = true;
else if (*input == LONG_FLAGS_OPEN)
else if (c == LONG_FLAGS_OPEN)
{
if (flags)
*flags = input;
break;
}
else
vStringPut (vdesc, *input);
vStringPut (vdesc, c);
input++;
}
return vStringDeleteUnwrap(vdesc);
Expand Down Expand Up @@ -4855,7 +4855,7 @@ static bool makeKindDescriptionPseudoTag (kindDefinition *kind,

letter_and_name = vStringNew ();

vStringPut (letter_and_name, kind -> letter);
vStringPut (letter_and_name, (unsigned char) kind -> letter);
vStringPut (letter_and_name, ',');
vStringCatS (letter_and_name, kind -> name);

Expand Down
2 changes: 1 addition & 1 deletion main/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ static vString *readFileName (char *s)
while (*s != '\0' && *s != '\n' &&
(quoteDelimited ? (*s != '"') : (*s != ' ' && *s != '\t')))
{
vStringPut (fileName, *s);
vStringPut (fileName, (unsigned char) *s);
s++;
}
vStringPut (fileName, '\0');
Expand Down
2 changes: 1 addition & 1 deletion main/sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static void appendCstringWithQuotes (vString *dest, const char* cstr)
if (*o == '\'')
vStringCatS (dest, "'\"'\"'");
else
vStringPut (dest, *o);
vStringPut (dest, (unsigned char) *o);
}
vStringPut (dest, '\'');
#endif
Expand Down
4 changes: 2 additions & 2 deletions main/vstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ extern void vStringCatSWithEscaping (vString* b, const char *s)
continue;
}
}
vStringPut (b, c);
vStringPut (b, (unsigned char) c);
}
}

Expand All @@ -356,7 +356,7 @@ extern void vStringCatSWithEscapingAsPattern (vString *output, const char* input
vStringPut(output, '/');
break;
default:
vStringPut(output, *input);
vStringPut(output, (unsigned char) *input);
break;

}
Expand Down
2 changes: 1 addition & 1 deletion old-docs/EXTENDING.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ <h2>Examples</h2>
++cp;
while (isalnum ((int) *cp) || *cp == '_')
{
vStringPut (name, (int) *cp);
vStringPut (name, *cp);
++cp;
}
makeSimpleTag (name, SwineKinds, K_DEFINE);
Expand Down
2 changes: 1 addition & 1 deletion parsers/abaqus.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void createTag(AbaqusKind kind, const char *buf)

do
{
vStringPut(name, (int) *buf);
vStringPut(name, (unsigned char) *buf);
++buf;
} while ((*buf != '\0') && (*buf != ','));
makeSimpleTag(name, kind);
Expand Down
Loading

0 comments on commit 913aefc

Please sign in to comment.