From f34a71195e288439e29bc678856b55de2b7af99e Mon Sep 17 00:00:00 2001 From: javalsai Date: Wed, 25 Dec 2024 20:22:28 +0100 Subject: [PATCH] chore: use `size_t` for indexing and iterating --- include/util.h | 3 ++- src/auth.c | 10 +++++----- src/chvt.c | 2 +- src/sessions.c | 2 +- src/ui.c | 6 +++--- src/util.c | 2 +- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/util.h b/include/util.h index 9bfcf8a..96b1a5a 100644 --- a/include/util.h +++ b/include/util.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "keys.h" @@ -25,6 +26,6 @@ void vec_free(struct Vector*); void vec_clear(struct Vector*); void vec_reset(struct Vector*); void* vec_pop(struct Vector*); // won't free it, nor shrink vec list space -void* vec_get(struct Vector*, uint32_t index); +void* vec_get(struct Vector*, size_t index); #endif diff --git a/src/auth.c b/src/auth.c index 11819e8..e041a89 100644 --- a/src/auth.c +++ b/src/auth.c @@ -19,7 +19,7 @@ int pam_conversation(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr) { struct pam_response *reply = (struct pam_response *)malloc(sizeof(struct pam_response) * num_msg); - for (int i = 0; i < num_msg; i++) { + for (size_t i = 0; i < num_msg; i++) { reply[i].resp = NULL; reply[i].resp_retcode = 0; if (msg[i]->msg_style == PAM_PROMPT_ECHO_OFF || @@ -79,7 +79,7 @@ void sourceFileTry(char *file) { /* printf("Retrieved line of length %zu:\n", read); */ /* printf("%s\n", line); */ - for (uint i = 1; i < read; i++) { + for (size_t i = 1; i < read; i++) { if (line[i] == '=') { /* printf("FOUND '='!\n"); */ line[i] = '\0'; @@ -118,7 +118,7 @@ void moarEnv(char *user, struct session session, struct passwd *pw, setenv("XDG_SESSION_TYPE", xdg_session_type, true); printf("\n\n\n\n\x1b[1m"); - for (uint32_t i = 0; i < behavior->source.length; i++) { + for (size_t i = 0; i < behavior->source.length; i++) { /* printf("DEBUG(source)!!!! %d %s\n", i, (char*)vec_get(&behavior->source, * i)); */ sourceFileTry((char *)vec_get(&behavior->source, i)); @@ -126,7 +126,7 @@ void moarEnv(char *user, struct session session, struct passwd *pw, /* printf("\n"); */ if (pw->pw_dir) { uint home_len = strlen(pw->pw_dir); - for (uint32_t i = 0; i < behavior->user_source.length; i++) { + for (size_t i = 0; i < behavior->user_source.length; i++) { char *file2sourcepath = (char *)vec_get(&behavior->user_source, i); char *newbuf = malloc(home_len + strlen(file2sourcepath) + 2); // nullbyte and slash @@ -190,7 +190,7 @@ bool launch(char *user, char *passwd, struct session session, void (*cb)(void), print_errno("pam_getenvlist"); _exit(EXIT_FAILURE); } - for (uint i = 0; envlist[i] != NULL; i++) { + for (size_t i = 0; envlist[i] != NULL; i++) { putenv(envlist[i]); } // FIXME: path hotfix diff --git a/src/chvt.c b/src/chvt.c index a78090b..34b9346 100644 --- a/src/chvt.c +++ b/src/chvt.c @@ -26,7 +26,7 @@ int chvt_str(char *str) { int chvt(int n) { fprintf(stderr, "activating vt %d\n", n); char c = 0; - for (int i = 0; i < sizeof(vterms) / sizeof(vterms[0]); i++) { + for (size_t i = 0; i < sizeof(vterms) / sizeof(vterms[0]); i++) { int fd = open(vterms[i], O_RDWR); if (fd >= 0 && isatty(fd) && ioctl(fd, KDGKBTYPE, &c) == 0 && c < 3) { if (ioctl(fd, VT_ACTIVATE, n) < 0 || ioctl(fd, VT_WAITACTIVE, n) < 0) { diff --git a/src/sessions.c b/src/sessions.c index e327f4f..c0ebbea 100644 --- a/src/sessions.c +++ b/src/sessions.c @@ -110,7 +110,7 @@ struct Vector get_avaliable_sessions() { struct Vector sessions = vec_new(); cb_sessions = &sessions; - for (uint i = 0; i < (sizeof(sources) / sizeof(sources[0])); i++) { + for (size_t i = 0; i < (sizeof(sources) / sizeof(sources[0])); i++) { /*printf("recurring into %s\n", sources[i].dir);*/ session_type = sources[i].type; ftw(sources[i].dir, &fn, 1); diff --git a/src/ui.c b/src/ui.c index bd944f3..f711554 100644 --- a/src/ui.c +++ b/src/ui.c @@ -500,15 +500,15 @@ static void print_passwd(struct uint_point origin, uint length, bool err) { } static void print_empty_row(uint w, uint n, char *edge1, char *edge2) { - for (uint i = 0; i < n; i++) { + for (size_t i = 0; i < n; i++) { printf("%s\x1b[%dC%s\x1b[%dD\x1b[1B", edge1, w, edge2, w + 2); } } static void print_row(uint w, uint n, char *edge1, char *edge2, char *filler) { - for (uint i = 0; i < n; i++) { + for (size_t i = 0; i < n; i++) { printf("%s", edge1); - for (uint i = 0; i < w; i++) { + for (size_t i = 0; i < w; i++) { printf("%s", filler); } printf("%s\x1b[%dD\x1b[1B", edge2, w + 2); diff --git a/src/util.c b/src/util.c index b6cdb4a..50a88a0 100644 --- a/src/util.c +++ b/src/util.c @@ -119,7 +119,7 @@ void* vec_pop(struct Vector* vec) { return vec->pages[--vec->length]; } -void* vec_get(struct Vector* vec, uint32_t index) { +void* vec_get(struct Vector* vec, size_t index) { if (index >= vec->length) return NULL;