Skip to content

Commit 5b18060

Browse files
authored
Merge pull request #69 from grimmy/ctype
Avoid undefined behavior with ctype functions
2 parents 42d0c8d + 53313e2 commit 5b18060

8 files changed

Lines changed: 14 additions & 13 deletions

File tree

COPYRIGHT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ Brian Macke
347347
Paolo Maggi
348348
Sulabh Mahajan
349349
Willian T. Mahan
350+
Anthony Mallet
350351
Jonathan Maltz
351352
Rok Mandeljc
352353
Tobias Markmann

gg/lib/dcc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ int gg_dcc_fill_file_info2(struct gg_dcc *d, const char *filename, const char *l
180180
ext = name + strlen(name);
181181

182182
for (i = 0, p = name; i < 8 && p < ext; i++, p++)
183-
d->file_info.short_filename[i] = toupper(name[i]);
183+
d->file_info.short_filename[i] = toupper((unsigned char)name[i]);
184184

185185
if (i == 8 && p < ext) {
186186
d->file_info.short_filename[6] = '~';
@@ -189,7 +189,7 @@ int gg_dcc_fill_file_info2(struct gg_dcc *d, const char *filename, const char *l
189189

190190
if (strlen(ext) > 0) {
191191
for (j = 0; *ext && j < 4; j++, p++)
192-
d->file_info.short_filename[i + j] = toupper(ext[j]);
192+
d->file_info.short_filename[i + j] = toupper((unsigned char)ext[j]);
193193
}
194194

195195
for (q = d->file_info.short_filename; *q; q++) {

gg/lib/events.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ static gg_action_t gg_handle_send_hub(struct gg_session *sess,
874874
int proxy;
875875
size_t req_len;
876876

877-
if (sess->client_version != NULL && isdigit(sess->client_version[0]))
877+
if (sess->client_version != NULL && isdigit((unsigned char)sess->client_version[0]))
878878
client = gg_urlencode(sess->client_version);
879879
else if (sess->protocol_version <= GG_PROTOCOL_VERSION_100)
880880
client = gg_urlencode(GG_DEFAULT_CLIENT_VERSION_100);

gg/lib/handlers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static int gg_session_handle_welcome_110(struct gg_session *gs, uint32_t seed,
117117
return -1;
118118
}
119119

120-
if (gs->client_version != NULL && !isdigit(gs->client_version[0])) {
120+
if (gs->client_version != NULL && !isdigit((unsigned char)gs->client_version[0])) {
121121
client_name = "";
122122
client_target = "";
123123
}
@@ -314,7 +314,7 @@ static int gg_session_handle_welcome(struct gg_session *gs, uint32_t type,
314314
l80.image_size = gs->image_size;
315315
l80.dunno2 = 0x64;
316316

317-
if (gs->client_version != NULL && !isdigit(gs->client_version[0])) {
317+
if (gs->client_version != NULL && !isdigit((unsigned char)gs->client_version[0])) {
318318
client_name = "";
319319
client_name_len = 0;
320320
} else {

gg/lib/message.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ size_t gg_message_html_to_text(char *dst, unsigned char *format,
694694
*format_len = 0;
695695

696696
for (src = html; *src != 0; src++) {
697-
if (in_entity && !(isalnum(*src) || *src == '#' || *src == ';')) {
697+
if (in_entity && !(isalnum((unsigned char)*src) || *src == '#' || *src == ';')) {
698698
int first = 1;
699699
size_t i, append_len = src - entity;
700700

@@ -738,7 +738,7 @@ size_t gg_message_html_to_text(char *dst, unsigned char *format,
738738
int i, ok = 1;
739739

740740
for (i = 0; i < 16; i++) {
741-
if (!isxdigit(tag[i])) {
741+
if (!isxdigit((unsigned char)tag[i])) {
742742
ok = 0;
743743
break;
744744
}
@@ -839,7 +839,7 @@ size_t gg_message_html_to_text(char *dst, unsigned char *format,
839839
break;
840840

841841
for (i = 0; i < 6; i++) {
842-
if (!isxdigit(tag[i])) {
842+
if (!isxdigit((unsigned char)tag[i])) {
843843
ok = 0;
844844
break;
845845
}
@@ -914,7 +914,7 @@ size_t gg_message_html_to_text(char *dst, unsigned char *format,
914914
continue;
915915
}
916916

917-
if (in_entity && !(isalnum(*src) || *src == '#'))
917+
if (in_entity && !(isalnum((unsigned char)*src) || *src == '#'))
918918
in_entity = 0;
919919

920920
if (in_entity)

novell/nmconn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ nm_read_header(NMConn * conn)
512512
ptr++;
513513

514514
i = 0;
515-
while (isdigit(*ptr) && (i < 3)) {
515+
while (isdigit((unsigned char)*ptr) && (i < 3)) {
516516
rtn_buf[i] = *ptr;
517517
i++;
518518
ptr++;

zephyr/ZVariables.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ varline(char *bfr, char *var)
196196
return (0);
197197

198198
cp = bfr;
199-
while (*cp && !isspace(*cp) && (*cp != '='))
199+
while (*cp && !isspace((unsigned char)*cp) && (*cp != '='))
200200
cp++;
201201

202202
#ifndef WIN32
@@ -211,7 +211,7 @@ varline(char *bfr, char *var)
211211
if (!cp)
212212
return(0);
213213
cp++;
214-
while (*cp && isspace(*cp)) /* space up to variable value */
214+
while (*cp && isspace((unsigned char)*cp)) /* space up to variable value */
215215
cp++;
216216

217217
return (cp - bfr); /* return index */

zephyr/zephyr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ static char *zephyr_to_html(const char *message)
630630
message += 2;
631631
} else if (*message == '@') {
632632
int end;
633-
for (end = 1; message[end] && (isalnum(message[end]) || message[end] == '_'); end++);
633+
for (end = 1; message[end] && (isalnum((unsigned char)message[end]) || message[end] == '_'); end++);
634634
if (message[end] &&
635635
(message[end] == '{' || message[end] == '[' || message[end] == '(' ||
636636
!g_ascii_strncasecmp(message + end, "&lt;", 4))) {

0 commit comments

Comments
 (0)