move to codeberg and fix memory leaks (#1)

This commit is contained in:
T. von Dein
2025-11-05 22:31:56 +01:00
parent 5c29ef69e0
commit 1ef2e34511
6 changed files with 191 additions and 157 deletions

View File

@@ -27,39 +27,35 @@ int *incr_dicedigit(int *digits) {
be a multiple of 10000, the 2nd a multiple of 1000 and so on.
*/
if(digits[4] == 6) {
if (digits[4] == 6) {
digits[4] = 1;
if(digits[3] == 60) {
if (digits[3] == 60) {
digits[3] = 10;
if(digits[2] == 600) {
digits[2] = 100;
if(digits[1] == 6000) {
digits[1] = 1000;
digits[0] += 10000; /* may overflow to 71111, must be catched by caller */
}
else
digits[1] += 1000;
}
else
digits[2] += 100;
}
else
if (digits[2] == 600) {
digits[2] = 100;
if (digits[1] == 6000) {
digits[1] = 1000;
digits[0] +=
10000; /* may overflow to 71111, must be catched by caller */
} else
digits[1] += 1000;
} else
digits[2] += 100;
} else
digits[3] += 10;
}
else
} else
digits[4]++;
return digits;
}
int get_dicenum(int *digits) {
/*
get the actual number of an array of dice digits
*/
int i = 0;
int pos = 0;
for(i=0; i<5; i++)
for (i = 0; i < 5; i++)
pos += digits[i];
return pos;
@@ -82,73 +78,72 @@ char **fetch_dict(char *dictfile) {
FILE *DICT;
int *digits;
if((DICT = fopen(dictfile, "rb")) == NULL) {
if ((DICT = fopen(dictfile, "rb")) == NULL) {
perror("Could not open dictfile");
exit(1);
}
words = malloc(66666 * sizeof(char *));
words = malloc(66667 * sizeof(char *));
digits = malloc(5 * sizeof(int));
jump = rand_lim(32);
digits[0] = 10000;
digits[1] = 1000;
digits[2] = 100;
digits[3] = 10;
digits[4] = 1;
pos = 11111;
digits[0] = 10000;
digits[1] = 1000;
digits[2] = 100;
digits[3] = 10;
digits[4] = 1;
pos = 11111;
next = 0;
for(i=0; i<6666; i++)
for (i = 0; i < 66667; i++)
words[i] = NULL;
LOOP:
LOOP:
while ((linelen = getline(&line, &len, DICT)) != -1) {
if(! dontjump) {
if(jump > 0) {
jump--;
continue;
}
else {
jump = rand_lim(32);
if (!dontjump) {
if (jump > 0) {
jump--;
continue;
} else {
jump = rand_lim(32);
}
}
if(linelen >= WMIN+1 && linelen <= WMAX+1) {
line[linelen-1] = '\0'; /* remove newline */
if (linelen >= WMIN + 1 && linelen <= WMAX + 1) {
line[linelen - 1] = '\0'; /* remove newline */
for(i=0; i<linelen-1; i++) {
if(isalnum((int)line[i]) == 0) {
next = 1;
break;
}
for (i = 0; i < linelen - 1; i++) {
if (isalnum((int)line[i]) == 0) {
next = 1;
break;
}
}
if(next) {
next = 0;
continue;
if (next) {
next = 0;
continue;
}
words[pos] = malloc(linelen);
strncpy( words[pos], line, linelen);
if(verbose > 1)
debug("add to wordlist at index %d: %s", pos, line);
strncpy(words[pos], line, linelen);
if (verbose > 1)
debug("add to wordlist at index %d: %s", pos, line);
digits = incr_dicedigit(digits);
pos = get_dicenum(digits);
/* this is what pos gets next after 66666, which is max reachable with 5 dices */
if(pos == 71111)
break;
/* this is what pos gets next after 66666, which is max reachable with 5
* dices */
if (pos == 71111)
break;
} /* endif word 4<=>10 */
} /* while read */
if(pos < 66666) {
if (pos < 66666) {
fseek(DICT, 0L, SEEK_SET);
goto LOOP;
}
fclose(DICT);
free(line);
free(digits);