reflow

Преобликује пасусе у редове
git clone https://git.sr.ht/~strahinja/reflow
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 10457f4fe248b47ff95617e742bb2296d683b747
родитељ 57136a65f21e87c285386608a745bcbfa77e0a95
Аутор: Страхиња Радић <sr@strahinja.org>
Датум:   Thu, 19 Mar 2026 13:55:25 +0000

reflow.c: Use memccpy; small fixes; update copyright year

Diffstat:
Mreflow.1.in | 4++--
Mreflow.c | 27+++++++++++++++------------
измењених датотека: 2, додавања: 17(+), брисања: 14(-)

diff --git a/reflow.1.in b/reflow.1.in @@ -1,5 +1,5 @@ .\" This program is licensed under the terms of GNU GPL v3 or (at your option) -.\" any later version. Copyright (C) 2021-2025 Страхиња Радић. +.\" any later version. Copyright (C) 2021-2026 Страхиња Радић. .\" See the file LICENSE for exact copyright and license details. .Dd %DATE% .Dt REFLOW 1 @@ -39,7 +39,7 @@ Print program version and commit date. .Ex -std .Sh AUTHORS .An Strahinya Radich Aq Mt sr@strahinja.org , -2021\-2025 +2021\-2026 .Sh BUGS Bugs can be reported using the ticket tracker at: .Lk https://\:todo.sr.ht/\:~strahinja/\:text-tools diff --git a/reflow.c b/reflow.c @@ -1,5 +1,5 @@ /* This program is licensed under the terms of GNU GPL v3 or (at your option) - * any later version. Copyright (C) 2021-2025 Страхиња Радић. + * any later version. Copyright (C) 2021-2026 Страхиња Радић. * See the file LICENSE for exact copyright and license details. */ #include <assert.h> @@ -15,7 +15,7 @@ #define COPYRIGHT \ (" This program is licensed under the terms of GNU GPL v3" \ " or (at your option)\n" \ - " any later version. Copyright (C) 2021-2025 Strahinya Radich.\n" \ + " any later version. Copyright (C) 2021-2026 Strahinya Radich.\n" \ " See the file LICENSE for exact copyright and license " \ "details.") @@ -88,7 +88,11 @@ main(int argc, char** argv) else if (!strcmp(carg, "-v") || !strcmp(carg, "--version")) return version(0); else if (!*filename) - strcpy(filename, carg); + { + if (!memccpy(filename, carg, 0, MAXPATH)) + return error(1, + "Overflow when setting filename"); + } else return usage(); argn++; @@ -133,7 +137,7 @@ main(int argc, char** argv) else { ssize_t pbuffer_start = pbuffer - buffer; - tempb = realloc(buffer, buffer_size + 1); + tempb = realloc(buffer, buffer_size + 1); if (!tempb) exit(error(ENOMEM, "Memory allocation failed")); buffer = tempb; @@ -153,7 +157,7 @@ main(int argc, char** argv) } else if (!((pline + 1 - line) < line_len && is_whitespace(*pline) - && is_whitespace(*(pline + 1)))) + && is_whitespace(pline[1]))) *pbuffer++ = *pline; pline++; } @@ -190,17 +194,16 @@ main(int argc, char** argv) strncpy(line, pbuffer, line_len); *(line + line_len) = 0; printf("%s", line); - if (*(pbuffer + line_len + 1) == '\n' && !empty_line) + if (pbuffer[line_len + 1] == '\n' && !empty_line) printf("\n\n"); - else if (!empty_line - && !is_whitespace(*(pbuffer + line_len - 1)) - && !is_whitespace(*(pbuffer + line_len + 1)) - && *(pbuffer + line_len - 1) != '\n' - && *(pbuffer + line_len + 1) != '\n') + else if (!empty_line && !is_whitespace(pbuffer[line_len - 1]) + && !is_whitespace(pbuffer[line_len + 1]) + && pbuffer[line_len - 1] != '\n' + && pbuffer[line_len + 1] != '\n') printf(" "); pbuffer += line_len + 1; } - printf("\n"); + puts(""); free(buffer); free(line);