Skip to content

Commit

Permalink
Fix format string conversion specifiers (#6192)
Browse files Browse the repository at this point in the history
Signed-off-by: Juuso Alasuutari <[email protected]>
Co-authored-by: Stefano Sinigardi <[email protected]>
  • Loading branch information
imaami and cenit authored Aug 26, 2023
1 parent c87e33e commit 68100fb
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/blas.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ float find_sim(size_t i, size_t j, contrastive_params *contrast_p, int contrast_
if (contrast_p[z].i == i && contrast_p[z].j == j) break;
}
if (z == contrast_p_size) {
printf(" Error: find_sim(): sim isn't found: i = %d, j = %d, z = %d \n", i, j, z);
printf(" Error: find_sim(): sim isn't found: i = %zu, j = %zu, z = %zu \n", i, j, z);
getchar();
}

Expand All @@ -608,7 +608,7 @@ float find_P_constrastive(size_t i, size_t j, contrastive_params *contrast_p, in
if (contrast_p[z].i == i && contrast_p[z].j == j) break;
}
if (z == contrast_p_size) {
printf(" Error: find_P_constrastive(): P isn't found: i = %d, j = %d, z = %d \n", i, j, z);
printf(" Error: find_P_constrastive(): P isn't found: i = %zu, j = %zu, z = %zu \n", i, j, z);
getchar();
}

Expand Down Expand Up @@ -648,7 +648,7 @@ float P_constrastive_f_det(size_t il, int *labels, float **z, unsigned int featu
float P_constrastive_f(size_t i, size_t l, int *labels, float **z, unsigned int feature_size, float temperature, contrastive_params *contrast_p, int contrast_p_size)
{
if (i == l) {
fprintf(stderr, " Error: in P_constrastive must be i != l, while i = %d, l = %d \n", i, l);
fprintf(stderr, " Error: in P_constrastive must be i != l, while i = %zu, l = %zu \n", i, l);
getchar();
}

Expand Down Expand Up @@ -782,7 +782,7 @@ void grad_contrastive_loss_negative_f(size_t i, int *class_ids, int *labels, siz
float P_constrastive(size_t i, size_t l, int *labels, size_t num_of_samples, float **z, unsigned int feature_size, float temperature, float *cos_sim, float *exp_cos_sim)
{
if (i == l) {
fprintf(stderr, " Error: in P_constrastive must be i != l, while i = %d, l = %d \n", i, l);
fprintf(stderr, " Error: in P_constrastive must be i != l, while i = %zu, l = %zu \n", i, l);
getchar();
}

Expand Down
2 changes: 1 addition & 1 deletion src/captcha.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void train_captcha(char *cfgfile, char *weightfile)
float loss = train_network(net, train);
if(avg_loss == -1) avg_loss = loss;
avg_loss = avg_loss*.9 + loss*.1;
printf("%d: %f, %f avg, %lf seconds, %ld images\n", i, loss, avg_loss, sec(clock()-time), *net.seen);
printf("%d: %f, %f avg, %lf seconds, %" PRIu64 " images\n", i, loss, avg_loss, sec(clock()-time), *net.seen);
free_data(train);
if(i%100==0){
char buff[256];
Expand Down
4 changes: 2 additions & 2 deletions src/cifar.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void train_cifar(char *cfgfile, char *weightfile)
float loss = train_network_sgd(net, train, 1);
if(avg_loss == -1) avg_loss = loss;
avg_loss = avg_loss*.95 + loss*.05;
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %ld images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen);
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %" PRIu64 " images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen);
if(*net.seen/N > epoch){
epoch = *net.seen/N;
char buff[256];
Expand Down Expand Up @@ -85,7 +85,7 @@ void train_cifar_distill(char *cfgfile, char *weightfile)
float loss = train_network_sgd(net, train, 1);
if(avg_loss == -1) avg_loss = loss;
avg_loss = avg_loss*.95 + loss*.05;
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %ld images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen);
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %" PRIu64 " images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen);
if(*net.seen/N > epoch){
epoch = *net.seen/N;
char buff[256];
Expand Down
2 changes: 1 addition & 1 deletion src/classifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int *gpus,
if (avg_time < 0) avg_time = time_remaining;
else avg_time = alpha_time * time_remaining + (1 - alpha_time) * avg_time;
start = what_time_is_it_now();
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %ld images, %f hours left\n", get_current_batch(net), (float)(*net.seen)/ train_images_num, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen, avg_time);
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %" PRIu64 " images, %f hours left\n", get_current_batch(net), (float)(*net.seen)/ train_images_num, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen, avg_time);
#ifdef OPENCV
if (net.contrastive) {
float cur_con_acc = -1;
Expand Down
6 changes: 3 additions & 3 deletions src/compare.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include <stdio.h>

#include "network.h"
#include "detection_layer.h"
#include "cost_layer.h"
#include "utils.h"
#include "parser.h"
#include "box.h"

#include <stdio.h>

void train_compare(char *cfgfile, char *weightfile)
{
srand(time(0));
Expand Down Expand Up @@ -54,7 +54,7 @@ void train_compare(char *cfgfile, char *weightfile)
float loss = train_network(net, train);
if(avg_loss == -1) avg_loss = loss;
avg_loss = avg_loss*.9 + loss*.1;
printf("%.3f: %f, %f avg, %lf seconds, %ld images\n", (float)*net.seen/N, loss, avg_loss, sec(clock()-time), *net.seen);
printf("%.3f: %f, %f avg, %lf seconds, %" PRIu64 " images\n", (float)*net.seen/N, loss, avg_loss, sec(clock()-time), *net.seen);
free_data(train);
if(i%100 == 0){
char buff[256];
Expand Down
12 changes: 6 additions & 6 deletions src/dark_cuda.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,14 @@ void free_pinned_memory()
void pre_allocate_pinned_memory(const size_t size)
{
const size_t num_of_blocks = size / pinned_block_size + ((size % pinned_block_size) ? 1 : 0);
printf("pre_allocate... pinned_ptr = %p \n", pinned_ptr);
printf("pre_allocate... pinned_ptr = %p \n", (void *)pinned_ptr);

pthread_mutex_lock(&mutex_pinned);
if (!pinned_ptr) {
pinned_ptr = (float **)calloc(num_of_blocks, sizeof(float *));
if(!pinned_ptr) error("calloc failed in pre_allocate()", DARKNET_LOC);

printf("pre_allocate: size = %Iu MB, num_of_blocks = %Iu, block_size = %Iu MB \n",
printf("pre_allocate: size = %zu MB, num_of_blocks = %zu, block_size = %zu MB \n",
size / (1024*1024), num_of_blocks, pinned_block_size / (1024 * 1024));

int k;
Expand All @@ -402,7 +402,7 @@ void pre_allocate_pinned_memory(const size_t size)
CHECK_CUDA(status);
if (!pinned_ptr[k]) error("cudaHostAlloc failed", DARKNET_LOC);
else {
printf(" Allocated %d pinned block \n", pinned_block_size);
printf(" Allocated %zu pinned block \n", pinned_block_size);
}
}
pinned_num_of_blocks = num_of_blocks;
Expand All @@ -423,7 +423,7 @@ float *cuda_make_array_pinned_preallocated(float *x, size_t n)
{
if ((allocation_size + pinned_index) > pinned_block_size) {
const float filled = (float)100 * pinned_index / pinned_block_size;
printf("\n Pinned block_id = %d, filled = %f %% \n", pinned_block_id, filled);
printf("\n Pinned block_id = %zu, filled = %f %% \n", pinned_block_id, filled);
pinned_block_id++;
pinned_index = 0;
}
Expand All @@ -438,13 +438,13 @@ float *cuda_make_array_pinned_preallocated(float *x, size_t n)

if(!x_cpu) {
if (allocation_size > pinned_block_size / 2) {
printf("Try to allocate new pinned memory, size = %d MB \n", size / (1024 * 1024));
printf("Try to allocate new pinned memory, size = %zu MB \n", size / (1024 * 1024));
cudaError_t status = cudaHostAlloc((void **)&x_cpu, size, cudaHostRegisterMapped);
if (status != cudaSuccess) fprintf(stderr, " Can't allocate CUDA-pinned memory on CPU-RAM (pre-allocated memory is over too) \n");
CHECK_CUDA(status);
}
else {
printf("Try to allocate new pinned BLOCK, size = %d MB \n", size / (1024 * 1024));
printf("Try to allocate new pinned BLOCK, size = %zu MB \n", size / (1024 * 1024));
pinned_num_of_blocks++;
pinned_block_id = pinned_num_of_blocks - 1;
pinned_index = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/dice.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void train_dice(char *cfgfile, char *weightfile)
float loss = train_network(net, train);
if(avg_loss == -1) avg_loss = loss;
avg_loss = avg_loss*.9 + loss*.1;
printf("%d: %f, %f avg, %lf seconds, %ld images\n", i, loss, avg_loss, sec(clock()-time), *net.seen);
printf("%d: %f, %f avg, %lf seconds, %" PRIu64 " images\n", i, loss, avg_loss, sec(clock()-time), *net.seen);
free_data(train);
if((i % 100) == 0) net.learning_rate *= .1;
if(i%100==0){
Expand Down
2 changes: 1 addition & 1 deletion src/go.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void train_go(char *cfgfile, char *weightfile)
float loss = train_network_datum(net, board, move) / net.batch;
if(avg_loss == -1) avg_loss = loss;
avg_loss = avg_loss*.95 + loss*.05;
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %ld images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen);
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %" PRIu64 " images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen);
if(*net.seen/N > epoch){
epoch = *net.seen/N;
char buff[256];
Expand Down
2 changes: 1 addition & 1 deletion src/http_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ class MJPG_sender
}

char head[400];
sprintf(head, "--mjpegstream\r\nContent-Type: image/jpeg\r\nContent-Length: %zu\r\n\r\n", outlen);
sprintf(head, "--mjpegstream\r\nContent-Type: image/jpeg\r\nContent-Length: %d\r\n\r\n", outlen);
_write(s, head, 0);
int n = _write(s, (char*)(&outbuf[0]), outlen);
cerr << "known client: " << s << ", sent = " << n << ", must be sent outlen = " << outlen << endl;
Expand Down
11 changes: 11 additions & 0 deletions src/network.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
// Oh boy, why am I about to do this....
#ifndef NETWORK_H
#define NETWORK_H

/*
* Necessary in C++ to get format macros out of inttypes.h
*/
#ifdef __cplusplus
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS 1
#endif
#endif
#include <inttypes.h>

#include "darknet.h"

#include <stdint.h>
Expand Down
2 changes: 1 addition & 1 deletion src/softmax_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ contrastive_layer make_contrastive_layer(int batch, int w, int h, int c, int cla
printf(" max_contr_size = %d MB \n", max_contr_size / (1024*1024));
l.contrast_p_gpu = (contrastive_params *)cuda_make_array(NULL, max_contr_size);
#endif
fprintf(stderr, "contrastive %4d x%4d x%4d x emb_size %4d x batch: %4d classes = %4d, step = %4d \n", w, h, l.n, l.embedding_size, batch, l.classes, step);
fprintf(stderr, "contrastive %4d x%4d x%4d x emb_size %4d x batch: %4d classes = %4d, step = %4zu \n", w, h, l.n, l.embedding_size, batch, l.classes, step);
if(l.detection) fprintf(stderr, "detection \n");
return l;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void train_tag(char *cfgfile, char *weightfile, int clear)
float loss = train_network(net, train);
if(avg_loss == -1) avg_loss = loss;
avg_loss = avg_loss*.9 + loss*.1;
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %ld images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen);
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %" PRIu64 " images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen);
free_data(train);
if(*net.seen/N > epoch){
epoch = *net.seen/N;
Expand Down
2 changes: 1 addition & 1 deletion src/writing.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void train_writing(char *cfgfile, char *weightfile)

if(avg_loss == -1) avg_loss = loss;
avg_loss = avg_loss*.9 + loss*.1;
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %ld images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen);
printf("%d, %.3f: %f, %f avg, %f rate, %lf seconds, %" PRIu64 " images\n", get_current_batch(net), (float)(*net.seen)/N, loss, avg_loss, get_current_rate(net), sec(clock()-time), *net.seen);
free_data(train);
if(get_current_batch(net)%100 == 0){
char buff[256];
Expand Down

0 comments on commit 68100fb

Please sign in to comment.