jcs
/amend
/amendments
/162
repo: Account for newlines in allocation in repo_diff_header
jcs made amendment 162 25 days ago
--- repo.c Thu Oct 24 21:50:38 2024
+++ repo.c Sun Sep 27 16:52:58 2026
@@ -388,10 +388,17 @@ repo_diff_header(struct repo *repo, struct repo_amendm
char **ret)
{
struct tm *ttm = NULL;
- unsigned short header_len;
+ unsigned short header_len, ncrs = 0;
short i;
- *ret = xmalloc(128 + amendment->log_len);
+ HLock(amendment->log);
+
+ for (i = 0; i < amendment->log_len; i++) {
+ if ((*(amendment->log))[i] == '\r')
+ ncrs++;
+ }
+
+ *ret = xmalloc(128 + amendment->log_len + (ncrs * 2) + 2);
ttm = localtime(&amendment->date);
header_len = snprintf(*ret, 128,
"Amendment: %d\r"
@@ -402,9 +409,10 @@ repo_diff_header(struct repo *repo, struct repo_amendm
amendment->author,
ttm->tm_year + 1900, ttm->tm_mon + 1, ttm->tm_mday,
ttm->tm_hour, ttm->tm_min, ttm->tm_sec);
-
+ if (header_len > 127)
+ header_len = 127;
+
/* copy log, indenting each line */
- HLock(amendment->log);
for (i = 0; i < amendment->log_len; i++) {
*(*ret + header_len++) = (*(amendment->log))[i];
@@ -425,7 +433,7 @@ repo_show_diff_text(struct repo *repo, struct repo_ame
TVHandle tv)
{
struct bile_object *bob;
- struct TVStyle style;
+ struct TVStyle style = { 0 };
size_t size;
char *dtext;
char *buf = NULL;