Skip to content

Commit cef6f59

Browse files
committed
Prefer size_t over int where possible
This avoids needless truncation, which takes up multiple more instructions on some architectures, especially older ones. Signed-off-by: Seija K.<doremylover123@gmail.com> Signed-off-by: Rose <83477269+AtariDreams@users.noreply.github.com>
1 parent 760ce18 commit cef6f59

12 files changed

Lines changed: 49 additions & 41 deletions

File tree

chat/chat.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,14 @@ struct termios saved_tty_parameters;
178178

179179
char *abort_string[MAX_ABORTS], *fail_reason = (char *)0,
180180
fail_buffer[50];
181-
int n_aborts = 0, abort_next = 0, timeout_next = 0, echo_next = 0;
181+
size_t n_aborts = 0;
182+
int abort_next = 0, timeout_next = 0, echo_next = 0;
182183
int clear_abort_next = 0;
183184

184185
char *report_string[MAX_REPORTS] ;
185186
char report_buffer[4096] ;
186-
int n_reports = 0, report_next = 0, report_gathering = 0 ;
187+
size_t n_reports = 0;
188+
int report_next = 0, report_gathering = 0 ;
187189
int clear_report_next = 0;
188190

189191
int say_next = 0, hup_next = 0;
@@ -606,9 +608,9 @@ void terminate(int status)
606608
* Allow the last of the report string to be gathered before we terminate.
607609
*/
608610
if (report_gathering) {
609-
int c, rep_len;
611+
int c;
610612

611-
rep_len = strlen(report_buffer);
613+
size_t rep_len = strlen(report_buffer);
612614
while (rep_len + 1 < sizeof(report_buffer)) {
613615
alarm(1);
614616
c = get_char();
@@ -1342,7 +1344,8 @@ int echo_stderr(int n)
13421344
int get_string(register char *string)
13431345
{
13441346
char temp[STR_LEN];
1345-
int c, printed = 0, len, minlen;
1347+
int c, printed = 0;
1348+
size_t len, minlen;
13461349
register char *s = temp, *end = s + STR_LEN;
13471350
char *s1, *logged = temp;
13481351

@@ -1372,7 +1375,7 @@ int get_string(register char *string)
13721375
alarmed = 0;
13731376

13741377
while ( ! alarmed && (c = get_char()) >= 0) {
1375-
int n, abort_len, report_len;
1378+
size_t n, abort_len, report_len;
13761379

13771380
if (echo) {
13781381
if (echo_stderr(c) != 0) {
@@ -1421,8 +1424,8 @@ int get_string(register char *string)
14211424
}
14221425
else {
14231426
if (!iscntrl (c)) {
1424-
int rep_len = strlen (report_buffer);
1425-
if ((rep_len + 1) < sizeof(report_buffer)) {
1427+
size_t rep_len = strlen (report_buffer);
1428+
if (rep_len < sizeof(report_buffer) - 1) {
14261429
report_buffer[rep_len] = c;
14271430
report_buffer[rep_len + 1] = '\0';
14281431
}

pppd/auth.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ static int
501501
setupapfile(char **argv)
502502
{
503503
FILE *ufile;
504-
int l;
504+
size_t l;
505505
uid_t euid;
506506
char u[MAXNAMELEN], p[MAXSECRETLEN];
507507
char *fname;
@@ -593,7 +593,7 @@ static int
593593
set_noauth_addr(char **argv)
594594
{
595595
char *addr = *argv;
596-
int l = strlen(addr) + 1;
596+
size_t l = strlen(addr) + 1;
597597
struct wordlist *wp;
598598

599599
wp = (struct wordlist *) malloc(sizeof(struct wordlist) + l);
@@ -614,7 +614,7 @@ static int
614614
set_permitted_number(char **argv)
615615
{
616616
char *number = *argv;
617-
int l = strlen(number) + 1;
617+
size_t l = strlen(number) + 1;
618618
struct wordlist *wp;
619619

620620
wp = (struct wordlist *) malloc(sizeof(struct wordlist) + l);
@@ -1831,7 +1831,8 @@ get_secret(int unit, char *client, char *server,
18311831
char *secret, int *secret_len, int am_server)
18321832
{
18331833
FILE *f;
1834-
int ret, len;
1834+
int ret;
1835+
size_t len;
18351836
char *filename;
18361837
struct wordlist *addrs, *opts;
18371838
char secbuf[MAXWORDLEN];
@@ -2154,22 +2155,24 @@ int
21542155
auth_number(void)
21552156
{
21562157
struct wordlist *wp = permitted_numbers;
2157-
int l;
2158+
size_t l;
21582159

21592160
/* Allow all if no authorization list. */
21602161
if (!wp)
21612162
return 1;
21622163

21632164
/* Allow if we have a match in the authorization list. */
2164-
while (wp) {
2165+
do {
21652166
/* trailing '*' wildcard */
21662167
l = strlen(wp->word);
2168+
if (l == 0)
2169+
return 1;
21672170
if ((wp->word)[l - 1] == '*')
21682171
l--;
21692172
if (!strncasecmp(wp->word, remote_number, l))
21702173
return 1;
21712174
wp = wp->next;
2172-
}
2175+
} while (wp);
21732176

21742177
return 0;
21752178
}

pppd/chap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ chap_client_timeout(void *arg)
310310
static void
311311
chap_generate_challenge(struct chap_server_state *ss)
312312
{
313-
int clen = 1, nlen, len;
313+
size_t clen = 1, nlen, len;
314314
unsigned char *p;
315315

316316
p = ss->challenge;
@@ -327,8 +327,8 @@ chap_generate_challenge(struct chap_server_state *ss)
327327
p = ss->challenge + PPP_HDRLEN;
328328
p[0] = CHAP_CHALLENGE;
329329
p[1] = ++ss->id;
330-
p[2] = len >> 8;
331-
p[3] = len;
330+
p[2] = (len >> 8) & 0xFF;
331+
p[3] = len & 0xFF;
332332
}
333333

334334
/*

pppd/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,9 +1824,9 @@ update_script_environment(void)
18241824
struct userenv *uep;
18251825

18261826
for (uep = userenv_list; uep != NULL; uep = uep->ue_next) {
1827-
int i;
1827+
size_t i;
18281828
char *p, *newstring;
1829-
int nlen = strlen(uep->ue_name);
1829+
size_t nlen = strlen(uep->ue_name);
18301830

18311831
for (i = 0; (p = script_env[i]) != NULL; i++) {
18321832
if (strncmp(p, uep->ue_name, nlen) == 0 && p[nlen] == '=')
@@ -2125,7 +2125,7 @@ ppp_script_setenv(char *var, char *value, int iskey)
21252125
{
21262126
size_t varl = strlen(var);
21272127
size_t vl = varl + strlen(value) + 2;
2128-
int i;
2128+
size_t i;
21292129
char *p, *newstring;
21302130

21312131
newstring = (char *) malloc(vl+1);
@@ -2184,7 +2184,7 @@ ppp_script_setenv(char *var, char *value, int iskey)
21842184
void
21852185
ppp_script_unsetenv(char *var)
21862186
{
2187-
int vl = strlen(var);
2187+
size_t vl = strlen(var);
21882188
int i;
21892189
char *p;
21902190

pppd/multilink.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ static void remove_bundle_link(void)
348348
TDB_DATA key, rec;
349349
char entry[32];
350350
char *p, *q;
351-
int l;
351+
size_t l;
352352

353353
key.dptr = blinks_id;
354354
key.dsize = strlen(blinks_id);
@@ -540,7 +540,7 @@ str_to_epdisc(struct epdisc *ep, char *str)
540540
char *p, *endp;
541541

542542
for (i = EPD_NULL; i <= EPD_PHONENUM; ++i) {
543-
int sl = strlen(endp_class_names[i]);
543+
size_t sl = strlen(endp_class_names[i]);
544544
if (strncasecmp(str, endp_class_names[i], sl) == 0) {
545545
str += sl;
546546
break;

pppd/options.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,8 @@ static int
16131613
callfile(char **argv)
16141614
{
16151615
char *fname, *arg, *p;
1616-
int l, ok;
1616+
size_t l;
1617+
int ok;
16171618

16181619
arg = *argv;
16191620
ok = 1;
@@ -1768,7 +1769,7 @@ loadplugin(char **argv)
17681769

17691770
if (strchr(arg, '/') == 0) {
17701771
const char *base = PPP_PATH_PLUGIN;
1771-
int l = strlen(base) + strlen(arg) + 2;
1772+
size_t l = strlen(base) + strlen(arg) + 2;
17721773
path = malloc(l);
17731774
if (path == 0)
17741775
novm("plugin file path");
@@ -1831,7 +1832,7 @@ user_setenv(char **argv)
18311832
return 0;
18321833
}
18331834
for (uep = userenv_list; uep != NULL; uep = uep->ue_next) {
1834-
int nlen = strlen(uep->ue_name);
1835+
size_t nlen = strlen(uep->ue_name);
18351836
if (nlen == (eqp - arg) &&
18361837
strncmp(arg, uep->ue_name, nlen) == 0)
18371838
break;

pppd/plugins/pppoatm/atm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,6 @@ int sap2text(char *buffer,int length,const struct atm_sap *sap,int flags);
103103
int sap_equal(const struct atm_sap *a,const struct atm_sap *b,int flags,...);
104104

105105
int __t2q_get_rate(const char **text,int up);
106-
int __atmlib_fetch(const char **pos,...); /* internal use only */
106+
size_t __atmlib_fetch(const char **pos,...); /* internal use only */
107107

108108
#endif

pppd/plugins/pppoatm/misc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
#include <atmsap.h>
1818

1919

20-
int __atmlib_fetch(const char **pos,...)
20+
size_t __atmlib_fetch(const char **pos,...)
2121
{
2222
const char *value;
23-
int ref_len,best_len,len;
24-
int i,best;
23+
size_t ref_len,best_len,len;
24+
size_t i,best;
2525
va_list ap;
2626

2727
va_start(ap,pos);
2828
ref_len = strlen(*pos);
2929
best_len = 0;
30-
best = -1;
30+
best = 0;
3131
for (i = 0; (value = va_arg(ap,const char *)); i++) {
3232
len = strlen(value);
3333
if (*value != '!' && len <= ref_len && len > best_len &&
@@ -37,7 +37,7 @@ int __atmlib_fetch(const char **pos,...)
3737
}
3838
}
3939
va_end(ap);
40-
if (best > -1) (*pos) += best_len;
40+
(*pos) += best_len;
4141
return best;
4242
}
4343

pppd/plugins/pppoatm/text2qos.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int text2qos(const char *text,struct atm_qos *qos,int flags)
130130
aal = ATM_NO_AAL;
131131
do {
132132
static const unsigned char aal_number[] = { ATM_AAL0, ATM_AAL5 };
133-
int item;
133+
size_t item;
134134

135135
item = fetch(&text,"!none","ubr","cbr","vbr","abr","aal0","aal5",NULL);
136136
switch (item) {

pppd/plugins/pppoe/pppoe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ void pppoe_log_packet(const char *prefix, PPPoEPacket *packet);
284284

285285
static inline int parseHostUniq(const char *uniq, PPPoETag *tag)
286286
{
287-
unsigned i, len = strlen(uniq);
287+
size_t i, len = strlen(uniq);
288288

289289
#define hex(x) \
290290
(((x) <= '9') ? ((x) - '0') : \

0 commit comments

Comments
 (0)