Skip to content

Commit a6eb92f

Browse files
authored
Merge pull request #92 from ixfd64/improvements--2025-11-08
General improvements (2025-11-08)
2 parents 0142b12 + 7538831 commit a6eb92f

File tree

3 files changed

+46
-28
lines changed

3 files changed

+46
-28
lines changed

.github/workflows/scripts/build_helper.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
#
2+
33
# This file is part of mfaktc.
44
# Copyright (c) 2025 NStorm (https://github.com/N-Storm)
55
# Copyright (c) 2009-2011 Oliver Weihe (o.weihe@t-online.de)

src/checkpoint.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ along with mfaktc. If not, see <http://www.gnu.org/licenses/>.
2828
#include "crc.h"
2929
#include "compatibility.h"
3030

31-
void checkpoint_write(unsigned int exp, int bit_min, int bit_max, int cur_class, int num_factors, int96 factors[MAX_FACTORS_PER_JOB],
32-
unsigned long long int bit_level_time)
3331
/*
3432
checkpoint_write() writes the checkpoint file.
3533
*/
34+
void checkpoint_write(unsigned int exp, int bit_min, int bit_max, int cur_class, int num_factors, int96 factors[MAX_FACTORS_PER_JOB],
35+
unsigned long long int bit_level_time)
3636
{
3737
FILE *f;
38-
char buffer[MAX_BUFFER_LENGTH], filename[MAX_CHECKPOINT_FILENAME_LENGTH], factors_buffer[MAX_FACTOR_BUFFER_LENGTH];
38+
char ckp_buffer[MAX_BUFFER_LENGTH], filename[MAX_CHECKPOINT_FILENAME_LENGTH], factors_buffer[MAX_FACTOR_BUFFER_LENGTH];
3939
unsigned int i, factors_buffer_length;
4040

4141
snprintf(filename, MAX_CHECKPOINT_FILENAME_LENGTH, "%s%u_%d-%d_%d.ckp", NAME_NUMBERS, exp, bit_min, bit_max, NUM_CLASSES);
@@ -58,18 +58,16 @@ checkpoint_write() writes the checkpoint file.
5858
if (f == NULL) {
5959
printf("Warning: could not write checkpoint file \"%s\"\n", filename);
6060
} else {
61-
sprintf(buffer, "%s%u %d %d %d %s: %d %d %s %llu", NAME_NUMBERS, exp, bit_min, bit_max, NUM_CLASSES, MFAKTC_CHECKPOINT_VERSION,
61+
sprintf(ckp_buffer, "%s%u %d %d %d %s: %d %d %s %llu", NAME_NUMBERS, exp, bit_min, bit_max, NUM_CLASSES, MFAKTC_CHECKPOINT_VERSION,
6262
cur_class, num_factors, strlen(factors_buffer) ? factors_buffer : "0", bit_level_time);
63-
i = crc32_checksum(buffer, strlen(buffer));
63+
i = crc32_checksum(ckp_buffer, strlen(ckp_buffer));
6464
fprintf(f, "%s%u %d %d %d %s: %d %d %s %llu %08X", NAME_NUMBERS, exp, bit_min, bit_max, NUM_CLASSES, MFAKTC_CHECKPOINT_VERSION,
6565
cur_class, num_factors, strlen(factors_buffer) ? factors_buffer : "0", bit_level_time, i);
6666
fclose(f);
6767
f = NULL;
6868
}
6969
}
7070

71-
int checkpoint_read(unsigned int exp, int bit_min, int bit_max, int *cur_class, int *num_factors, int96 factors[MAX_FACTORS_PER_JOB],
72-
unsigned long long int *bit_level_time)
7371
/*
7472
checkpoint_read() reads the checkpoint file and compares values for exp,
7573
bit_min, bit_max, NUM_CLASSES read from file with current values.
@@ -79,13 +77,13 @@ factors, and class_time to the values from the checkpoint file.
7977
returns 1 on success (valid checkpoint file)
8078
returns 0 otherwise
8179
*/
80+
int checkpoint_read(unsigned int exp, int bit_min, int bit_max, int *cur_class, int *num_factors, int96 factors[MAX_FACTORS_PER_JOB],
81+
unsigned long long int *bit_level_time)
8282
{
8383
FILE *f;
8484
int ret = 0, i, chksum, chksum_ckp, num_factors_ckp;
85-
char buffer[600], buffer2[600], *ptr, filename[40], factors_buffer[500];
86-
87-
for (i = 0; i < 600; i++)
88-
buffer[i] = 0;
85+
char ckp_buffer[MAX_BUFFER_LENGTH] = { 0 }, cur_buffer[MAX_BUFFER_LENGTH], *ptr, filename[MAX_CHECKPOINT_FILENAME_LENGTH],
86+
factors_buffer[MAX_FACTOR_BUFFER_LENGTH];
8987

9088
*cur_class = -1;
9189
*num_factors = 0;
@@ -96,24 +94,26 @@ returns 0 otherwise
9694
if (f == NULL) {
9795
return 0;
9896
}
99-
i = fread(buffer, sizeof(char), 599, f);
100-
sprintf(buffer2, "%s%u %d %d %d %s: ", NAME_NUMBERS, exp, bit_min, bit_max, NUM_CLASSES, MFAKTC_CHECKPOINT_VERSION);
97+
i = fread(ckp_buffer, sizeof(char), MAX_BUFFER_LENGTH - 1, f);
98+
sprintf(cur_buffer, "%s%u %d %d %d %s: ", NAME_NUMBERS, exp, bit_min, bit_max, NUM_CLASSES, MFAKTC_CHECKPOINT_VERSION);
10199

102-
ptr = strstr(buffer, buffer2);
103-
if (ptr == buffer) {
104-
i = strlen(buffer2);
100+
ptr = strstr(ckp_buffer, cur_buffer);
101+
if (ptr == ckp_buffer) {
102+
i = strlen(cur_buffer);
105103
if (i < 70) {
106-
ptr = &(buffer[i]);
104+
ptr = &(ckp_buffer[i]);
107105
sscanf(ptr, "%d %d %s %llu %08X", cur_class, &num_factors_ckp, factors_buffer, bit_level_time, &chksum_ckp);
108-
sprintf(buffer2, "%s%u %d %d %d %s: %d %d %s %llu", NAME_NUMBERS, exp, bit_min, bit_max, NUM_CLASSES, MFAKTC_CHECKPOINT_VERSION,
106+
sprintf(cur_buffer, "%s%u %d %d %d %s: %d %d %s %llu", NAME_NUMBERS, exp, bit_min, bit_max, NUM_CLASSES, MFAKTC_CHECKPOINT_VERSION,
109107
*cur_class, num_factors_ckp, factors_buffer, *bit_level_time);
110-
chksum = crc32_checksum(buffer2, strlen(buffer2));
111-
if (chksum != chksum_ckp) printf("Warning: checkpoint file checksum mismatch\n");
108+
chksum = crc32_checksum(cur_buffer, strlen(cur_buffer));
109+
if (chksum != chksum_ckp) {
110+
printf("Warning: checkpoint file checksum mismatch\n");
111+
}
112112

113-
sprintf(buffer2, "%s%u %d %d %d %s: %d %d %s %llu %08X", NAME_NUMBERS, exp, bit_min, bit_max, NUM_CLASSES,
113+
sprintf(cur_buffer, "%s%u %d %d %d %s: %d %d %s %llu %08X", NAME_NUMBERS, exp, bit_min, bit_max, NUM_CLASSES,
114114
MFAKTC_CHECKPOINT_VERSION, *cur_class, num_factors_ckp, factors_buffer, *bit_level_time, chksum);
115-
if (*cur_class >= 0 && *cur_class < NUM_CLASSES && num_factors_ckp >= 0 && strlen(buffer) == strlen(buffer2) &&
116-
strstr(buffer, buffer2) == buffer &&
115+
if (*cur_class >= 0 && *cur_class < NUM_CLASSES && num_factors_ckp >= 0 && strlen(ckp_buffer) == strlen(cur_buffer) &&
116+
strstr(ckp_buffer, cur_buffer) == ckp_buffer &&
117117
((num_factors_ckp == 0 && strlen(factors_buffer) == 1) || (num_factors_ckp >= 1 && strlen(factors_buffer) > 1))) {
118118
ret = 1;
119119

@@ -134,8 +134,8 @@ returns 0 otherwise
134134
}
135135
}
136136
if (*num_factors != num_factors_ckp)
137-
printf("Warning: checkpoint file reports %d factors, but %d are actually stored\n",
138-
num_factors_ckp, *num_factors);
137+
printf("Warning: checkpoint file reports %d factor%s, but %d %s actually stored\n", num_factors_ckp,
138+
num_factors_ckp == 1 ? "" : "s", *num_factors, *num_factors == 1 ? "is" : "are");
139139
}
140140
}
141141
}
@@ -145,12 +145,12 @@ returns 0 otherwise
145145
return ret;
146146
}
147147

148-
void checkpoint_delete(unsigned int exp, int bit_min, int bit_max)
149148
/*
150149
tries to delete the checkpoint file
151150
*/
151+
void checkpoint_delete(unsigned int exp, int bit_min, int bit_max)
152152
{
153-
char filename[40];
153+
char filename[MAX_CHECKPOINT_FILENAME_LENGTH];
154154
sprintf(filename, "%s%u_%d-%d_%d.ckp", NAME_NUMBERS, exp, bit_min, bit_max, NUM_CLASSES);
155155

156156
if (remove(filename)) {

src/create_dependencies.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
#!/bin/bash
22

3+
# This file is part of mfaktc.
4+
# Copyright (C) 2009-2025 Oliver Weihe (o.weihe@t-online.de)
5+
#
6+
# mfaktc is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# mfaktc is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with mfaktc. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
# SPDX-License-Identifier: GPL-3.0-or-later
20+
321
case "${1}" in
422
win)
523
OBJ="obj"

0 commit comments

Comments
 (0)