logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: ba108d9d984493d5b84b8d02b6bb99bab2886174
parent 55c740b9af4de8917dd94b94c411a7721cf2946d
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 30 Jan 2022 15:28:05 +0100

bin/strings: Clear warnings about type of `offset`

Diffstat:

Mbin/strings.c28+++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/bin/strings.c b/bin/strings.c @@ -15,20 +15,26 @@ size_t opt_min_strlen = 4; char *opt_offset_format = NULL; int -print_string(char *buffer, int offset) +print_string(char *buffer, size_t offset) { int ret = 0; - if(opt_offset_format == NULL) { + if(opt_offset_format == NULL) + { ret = printf("%s\n", buffer); - } else { + } + else + { ret = printf(opt_offset_format, offset, buffer); } - if(ret < 0) { + if(ret < 0) + { fprintf(stderr, "\nError writing: %s\n", strerror(errno)); return 1; - } else { + } + else + { return 0; } } @@ -40,16 +46,16 @@ concat(int fd, const char *fdname) char read_buf[4096]; char write_buf[4096]; size_t write_pos = 0; - int offset = 0; + size_t offset = 0; memset(write_buf, 0, sizeof(write_buf)); while((c = read(fd, read_buf, sizeof(read_buf))) > 0) { int read_pos = 0; - char b = 0; + char b = 0; - for(;read_pos < c; read_pos++) + for(; read_pos < c; read_pos++) { b = read_buf[read_pos]; @@ -121,9 +127,9 @@ main(int argc, char *argv[]) switch(optarg[0]) { - case 'o': opt_offset_format = "%o %s\n"; break; - case 'x': opt_offset_format = "%x %s\n"; break; - case 'd': opt_offset_format = "%d %s\n"; break; + case 'o': opt_offset_format = "%zo %s\n"; break; + case 'x': opt_offset_format = "%zx %s\n"; break; + case 'd': opt_offset_format = "%zd %s\n"; break; default: usage(); return 1; } break;