Skip to content

Commit 78d3bac

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: Rose <gfunni234@gmail.com>
1 parent 04e6b8d commit 78d3bac

12 files changed

Lines changed: 49 additions & 45 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+
unsigned long 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+
unsigned long 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: 8 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,22 @@ 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);
21672168
if ((wp->word)[l - 1] == '*')
21682169
l--;
21692170
if (!strncasecmp(wp->word, remote_number, l))
21702171
return 1;
21712172
wp = wp->next;
2172-
}
2173+
} while (wp);
21732174

21742175
return 0;
21752176
}

pppd/chap.c

Lines changed: 1 addition & 1 deletion
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;

pppd/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,9 +1863,9 @@ update_script_environment(void)
18631863
struct userenv *uep;
18641864

18651865
for (uep = userenv_list; uep != NULL; uep = uep->ue_next) {
1866-
int i;
1866+
size_t i;
18671867
char *p, *newstring;
1868-
int nlen = strlen(uep->ue_name);
1868+
size_t nlen = strlen(uep->ue_name);
18691869

18701870
for (i = 0; (p = script_env[i]) != NULL; i++) {
18711871
if (strncmp(p, uep->ue_name, nlen) == 0 && p[nlen] == '=')
@@ -2164,7 +2164,7 @@ ppp_script_setenv(char *var, char *value, int iskey)
21642164
{
21652165
size_t varl = strlen(var);
21662166
size_t vl = varl + strlen(value) + 2;
2167-
int i;
2167+
size_t i;
21682168
char *p, *newstring;
21692169

21702170
newstring = (char *) malloc(vl+1);
@@ -2223,8 +2223,8 @@ ppp_script_setenv(char *var, char *value, int iskey)
22232223
void
22242224
ppp_script_unsetenv(char *var)
22252225
{
2226-
int vl = strlen(var);
2227-
int i;
2226+
size_t vl = strlen(var);
2227+
size_t i;
22282228
char *p;
22292229

22302230
if (script_env == 0)

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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,8 @@ static int
16141614
callfile(char **argv)
16151615
{
16161616
char *fname, *arg, *p;
1617-
int l, ok;
1617+
size_t l;
1618+
int ok;
16181619

16191620
arg = *argv;
16201621
ok = 1;
@@ -1769,7 +1770,7 @@ loadplugin(char **argv)
17691770

17701771
if (strchr(arg, '/') == 0) {
17711772
const char *base = PPP_PATH_PLUGIN;
1772-
int l = strlen(base) + strlen(arg) + 2;
1773+
size_t l = strlen(base) + strlen(arg) + 2;
17731774
path = malloc(l);
17741775
if (path == 0)
17751776
novm("plugin file path");
@@ -1832,9 +1833,8 @@ user_setenv(char **argv)
18321833
return 0;
18331834
}
18341835
for (uep = userenv_list; uep != NULL; uep = uep->ue_next) {
1835-
int nlen = strlen(uep->ue_name);
1836-
if (nlen == (eqp - arg) &&
1837-
strncmp(arg, uep->ue_name, nlen) == 0)
1836+
size_t nlen = strlen(uep->ue_name);
1837+
if (nlen == (eqp - arg) && strncmp(arg, uep->ue_name, nlen) == 0)
18381838
break;
18391839
}
18401840
/* Ignore attempts by unprivileged users to override privileged sources */

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
@@ -285,7 +285,7 @@ void pppoe_log_packet(const char *prefix, PPPoEPacket *packet);
285285

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

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

0 commit comments

Comments
 (0)