Skip to content

Commit

Permalink
chore: use size_t for indexing and iterating
Browse files Browse the repository at this point in the history
  • Loading branch information
javalsai committed Dec 25, 2024
1 parent e13a8ff commit f34a711
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>

#include "keys.h"
Expand All @@ -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
10 changes: 5 additions & 5 deletions src/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -118,15 +118,15 @@ 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));
}
/* 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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/chvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/sessions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit f34a711

Please sign in to comment.