jcs
/amend
/amendments
/85
commit_list: Fix off-by-one in calculating log length
This would occasionally print a character of garbage after the log
depending on what was next in memory.
jcs made amendment 85 over 2 years ago
--- commit_list.c Tue Jan 11 20:31:37 2022
+++ commit_list.c Wed Aug 17 14:15:57 2022
@@ -21,11 +21,11 @@
#include "repo.h"
#include "util.h"
-void commit_list_draw_cell(ListHandle theList, Cell theCell,
+void amendment_list_draw_cell(ListHandle theList, Cell theCell,
short dataLen, Rect *cellRect, Boolean selected);
pascal void
-commit_list_ldef(short message, Boolean selected, Rect *cellRect,
+amendment_list_ldef(short message, Boolean selected, Rect *cellRect,
Cell theCell, short dataOffset, short dataLen, ListHandle theList)
{
short id;
@@ -39,7 +39,7 @@ commit_list_ldef(short message, Boolean selected, Rect
/* FALLTHROUGH */
case 2:
/* hilight */
- commit_list_draw_cell(theList, theCell, dataLen, cellRect,
+ amendment_list_draw_cell(theList, theCell, dataLen, cellRect,
selected);
break;
case 3:
@@ -49,7 +49,7 @@ commit_list_ldef(short message, Boolean selected, Rect
}
void
-commit_list_draw_cell(ListHandle theList, Cell theCell, short dataLen,
+amendment_list_draw_cell(ListHandle theList, Cell theCell, short dataLen,
Rect *cellRect, Boolean selected)
{
RgnHandle savedClip;
@@ -57,12 +57,12 @@ commit_list_draw_cell(ListHandle theList, Cell theCell
GrafPtr savedPort;
Rect textRect;
char tmp[50];
- struct repo_commit *commit = NULL;
+ struct repo_amendment *amendment = NULL;
struct tm *ttm = NULL;
short offset, len, height;
- LGetCell(&commit, &dataLen, theCell, theList);
- if (commit == NULL)
+ LGetCell(&amendment, &dataLen, theCell, theList);
+ if (amendment == NULL)
/* XXX: why does this happen? */
return;
@@ -79,15 +79,15 @@ commit_list_draw_cell(ListHandle theList, Cell theCell
TextSize(9);
MoveTo(textRect.left, textRect.top + 6);
- HLock(commit->log);
- for (len = 1; len <= commit->log_len; len++) {
- if ((*(commit->log))[len - 1] == '\r')
+ HLock(amendment->log);
+ for (len = 1; len < amendment->log_len; len++) {
+ if ((*(amendment->log))[len - 1] == '\r')
break;
}
- DrawText(*(commit->log), 0, len);
- HUnlock(commit->log);
+ DrawText(*(amendment->log), 0, len);
+ HUnlock(amendment->log);
- ttm = localtime(&commit->date);
+ ttm = localtime(&amendment->date);
snprintf(tmp, sizeof(tmp), "%04d-%02d-%02d %02d:%02d:%02d",
ttm->tm_year + 1900, ttm->tm_mon + 1, ttm->tm_mday,
ttm->tm_hour, ttm->tm_min, ttm->tm_sec);
@@ -96,10 +96,10 @@ commit_list_draw_cell(ListHandle theList, Cell theCell
DrawText(tmp, 0, strlen(tmp));
MoveTo(textRect.left + 140, textRect.top + height + 6);
- DrawText(commit->author, 0, strlen(commit->author));
+ DrawText(amendment->author, 0, strlen(amendment->author));
snprintf(tmp, sizeof(tmp), "%d (+), %d (-)",
- commit->adds, commit->subs);
+ amendment->adds, amendment->subs);
MoveTo(textRect.left + 220, textRect.top + height + 6);
DrawText(tmp, 0, strlen(tmp));