fix: Prevent crash in fteapot when rendering very narrow columns (#76)

Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Reviewed-on: #76
This commit is contained in:
Glen Whitney 2023-04-08 01:34:37 +00:00
parent efdd63d351
commit 118374c46e
5 changed files with 23 additions and 4 deletions

View File

@ -1,6 +1,14 @@
The new build system uses CMake (http://www.cmake.org). It handles
all platform differences.
Once all prerequisites are in place, you should be able to build teapot via
```
mkdir build
cd build
cmake ..
make
```
In addition to the information in the README.md file on prerequisites, here
are some additional guidelines:

View File

@ -1,5 +1,6 @@
#ifndef WK1_H
#define WK1_H
/* Functions for reading Lotus 1-2-3 file format. */
#include "sheet.h"

View File

@ -1,5 +1,7 @@
/* Notes */ /*{{{C}}}*//*{{{*/
/*
This file contains code to read the legacy binary XDR format for
spreadsheet files, typically written in files with the .tp extension.
xdr_enum() is unusable, because enum_t may have a different size than
an enum. The construction

View File

@ -1,5 +1,6 @@
#ifndef XDR_H
#define XDR_H
/* Functions used for reading the legacy XDR binary file format */
/* Thanks to curses. */
#if 0

View File

@ -78,6 +78,12 @@ class TeapotTable {open : {public Fl_Table}}
{draw_cell(TableContext context, int R, int C, int xx, int yy,
int W, int H)} {open return_type void} {code
{
// Fl_Table calls this function to draw each visible cell in the table.
// context specifies what part of the table is being drawn;
// R and C give the row and column of the cell in the table;
// xx and yy give the screen coordinates where the cell is to be drawn;
// and W and H give the width and height of the rectangle into which to
// draw.
char s[1024];
if (debug_level > 2)
printf("DRAW: %i @%i,%i - (%i,%i) %ix%i\\n",
@ -167,13 +173,14 @@ class TeapotTable {open : {public Fl_Table}}
if (sc.italic) cellfont |= FL_ITALIC;
fl_font(cellfont, 14);
size_t len = printvalue(s, sizeof(s), 0, quote, sc.fform,
sc.precision, cursheet, test);
size_t nlen = len;
size_t ulen = printvalue(s, sizeof(s), 0, quote, sc.fform,
sc.precision, cursheet, test);
ptrdiff_t len = ulen;
ptrdiff_t nlen = len;
int ww = 0, hh = 0;
fl_measure(s, ww, hh, 0);
while (ww > W-6) {
char *dc = mbspos(s+nlen-1, -1);
char *dc = mbspos(s+nlen, -1);
nlen = dc - s;
s[nlen] = (char)0;
ww = 0;