Commit ad1572f77f7179896c9211f34ec1d67ef67c7dc2

Kano 2013-07-06T20:17:17

size check get_datestamp/get_timestamp and remove unused cgpu->init

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);