size check get_datestamp/get_timestamp and remove unused cgpu->init
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
diff --git a/cgminer.c b/cgminer.c
index 99c5dd3..a03f986 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -358,13 +358,13 @@ static bool should_run(void)
return true;
}
-void get_datestamp(char *f, struct timeval *tv)
+void get_datestamp(char *f, size_t fsiz, struct timeval *tv)
{
struct tm *tm;
const time_t tmp_time = tv->tv_sec;
tm = localtime(&tmp_time);
- sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d]",
+ snprintf(f, fsiz, "[%d-%02d-%02d %02d:%02d:%02d]",
tm->tm_year + 1900,
tm->tm_mon + 1,
tm->tm_mday,
@@ -373,13 +373,13 @@ void get_datestamp(char *f, struct timeval *tv)
tm->tm_sec);
}
-void get_timestamp(char *f, struct timeval *tv)
+static void get_timestamp(char *f, size_t fsiz, struct timeval *tv)
{
struct tm *tm;
const time_t tmp_time = tv->tv_sec;
tm = localtime(&tmp_time);
- sprintf(f, "[%02d:%02d:%02d]",
+ snprintf(f, fsiz, "[%02d:%02d:%02d]",
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
@@ -3597,7 +3597,7 @@ static void set_curblock(char *hexstr, unsigned char *hash)
current_hash = bin2hex(hash_swap + 2, 8);
free(current_fullhash);
current_fullhash = bin2hex(block_hash_swap, 32);
- get_timestamp(blocktime, &block_timeval);
+ get_timestamp(blocktime, sizeof(blocktime), &block_timeval);
cg_wunlock(&ch_lock);
applog(LOG_INFO, "New block: %s... diff %s", current_hash, block_diff);
@@ -7717,7 +7717,7 @@ begin_bench:
cgtime(&total_tv_start);
cgtime(&total_tv_end);
- get_datestamp(datestamp, &total_tv_start);
+ get_datestamp(datestamp, sizeof(datestamp), &total_tv_start);
// Start threads
k = 0;
diff --git a/driver-avalon.c b/driver-avalon.c
index d9606ac..57eae78 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -985,7 +985,6 @@ static bool avalon_prepare(struct thr_info *thr)
{
struct cgpu_info *avalon = thr->cgpu;
struct avalon_info *info = avalon->device_data;
- struct timeval now;
free(avalon->works);
avalon->works = calloc(info->miner_count * sizeof(struct work *),
@@ -1008,8 +1007,6 @@ static bool avalon_prepare(struct thr_info *thr)
avalon_init(avalon);
- cgtime(&now);
- get_datestamp(avalon->init, &now);
return true;
}
diff --git a/driver-bflsc.c b/driver-bflsc.c
index f3800c0..9b11ee5 100644
--- a/driver-bflsc.c
+++ b/driver-bflsc.c
@@ -1781,7 +1781,6 @@ static bool bflsc_thread_prepare(struct thr_info *thr)
{
struct cgpu_info *bflsc = thr->cgpu;
struct bflsc_info *sc_info = (struct bflsc_info *)(bflsc->device_data);
- struct timeval now;
if (thr_info_create(&(sc_info->results_thr), NULL, bflsc_get_results, (void *)bflsc)) {
applog(LOG_ERR, "%s%i: thread create failed", bflsc->drv->name, bflsc->device_id);
@@ -1789,9 +1788,6 @@ static bool bflsc_thread_prepare(struct thr_info *thr)
}
pthread_detach(sc_info->results_thr.pth);
- cgtime(&now);
- get_datestamp(bflsc->init, &now);
-
return true;
}
diff --git a/driver-bitforce.c b/driver-bitforce.c
index a2d19b5..07a2683 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -306,13 +306,9 @@ static void get_bitforce_statline_before(char *buf, size_t bufsiz, struct cgpu_i
tailsprintf(buf, bufsiz, " | ");
}
-static bool bitforce_thread_prepare(struct thr_info *thr)
+static bool bitforce_thread_prepare(__maybe_unused struct thr_info *thr)
{
- struct cgpu_info *bitforce = thr->cgpu;
- struct timeval now;
-
- cgtime(&now);
- get_datestamp(bitforce->init, &now);
+// struct cgpu_info *bitforce = thr->cgpu;
return true;
}
diff --git a/driver-icarus.c b/driver-icarus.c
index b6e2817..a0c44bb 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -839,14 +839,9 @@ static void icarus_detect()
usb_detect(&icarus_drv, icarus_detect_one);
}
-static bool icarus_prepare(struct thr_info *thr)
+static bool icarus_prepare(__maybe_unused struct thr_info *thr)
{
- struct cgpu_info *icarus = thr->cgpu;
-
- struct timeval now;
-
- cgtime(&now);
- get_datestamp(icarus->init, &now);
+// struct cgpu_info *icarus = thr->cgpu;
return true;
}
diff --git a/driver-modminer.c b/driver-modminer.c
index 37cb02e..bfe3040 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -569,13 +569,9 @@ dame:
static bool modminer_fpga_prepare(struct thr_info *thr)
{
- struct cgpu_info *modminer = thr->cgpu;
- struct timeval now;
-
- cgtime(&now);
- get_datestamp(modminer->init, &now);
-
+// struct cgpu_info *modminer = thr->cgpu;
struct modminer_fpga_state *state;
+
state = thr->cgpu_data = calloc(1, sizeof(struct modminer_fpga_state));
state->shares_to_good = MODMINER_EARLY_UP;
state->overheated = false;
diff --git a/driver-opencl.c b/driver-opencl.c
index 4f5ee69..3350eb8 100644
--- a/driver-opencl.c
+++ b/driver-opencl.c
@@ -698,7 +698,7 @@ retry:
thr = get_thread(i);
if (thr->cgpu != cgpu)
continue;
- get_datestamp(checkin, &thr->last);
+ get_datestamp(checkin, sizeof(checkin), &thr->last);
displayed_rolling = thr->rolling;
if (!mhash_base)
displayed_rolling *= 1000;
@@ -1197,7 +1197,7 @@ select_cgpu:
}
cgtime(&now);
- get_datestamp(cgpu->init, &now);
+ get_datestamp(cgpu->init, sizeof(cgpu->init), &now);
for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
thr = get_thread(thr_id);
@@ -1382,7 +1382,7 @@ static bool opencl_thread_prepare(struct thr_info *thr)
}
applog(LOG_INFO, "initCl() finished. Found %s", name);
cgtime(&now);
- get_datestamp(cgpu->init, &now);
+ get_datestamp(cgpu->init, sizeof(cgpu->init), &now);
have_opencl = true;
diff --git a/driver-ztex.c b/driver-ztex.c
index ba6d8cf..0283362 100644
--- a/driver-ztex.c
+++ b/driver-ztex.c
@@ -372,13 +372,9 @@ static void ztex_statline_before(char *buf, size_t bufsiz, struct cgpu_info *cgp
static bool ztex_prepare(struct thr_info *thr)
{
- struct timeval now;
struct cgpu_info *cgpu = thr->cgpu;
struct libztex_device *ztex = cgpu->device_ztex;
- cgtime(&now);
- get_datestamp(cgpu->init, &now);
-
ztex_selectFpga(ztex);
if (libztex_configureFpga(ztex) != 0) {
libztex_resetFpga(ztex);
diff --git a/miner.h b/miner.h
index c054325..731cba8 100644
--- a/miner.h
+++ b/miner.h
@@ -1284,7 +1284,7 @@ struct modminer_fpga_state {
strcat(buf, tmp13); \
} while (0)
-extern void get_datestamp(char *, struct timeval *);
+extern void get_datestamp(char *, size_t, struct timeval *);
extern void inc_hw_errors(struct thr_info *thr);
extern bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
extern struct work *get_queued(struct cgpu_info *cgpu);