Treat textlist item number as int instead of short

cf. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=838952
This commit is contained in:
Tatsuya Kinoshita
2021-03-30 20:15:07 +09:00
parent ac59b52134
commit 1a9bcdf202
4 changed files with 17 additions and 8 deletions

View File

@@ -119,7 +119,8 @@ unshiftHist(Hist *hist, char *ptr)
{ {
HistItem *item; HistItem *item;
if (hist == NULL || hist->list == NULL) if (hist == NULL || hist->list == NULL ||
hist->list->nitem >= HIST_LIST_MAX)
return NULL; return NULL;
item = (HistItem *)newListItem((void *)allocStr(ptr, -1), item = (HistItem *)newListItem((void *)allocStr(ptr, -1),
(ListItem *)hist->list->first, NULL); (ListItem *)hist->list->first, NULL);
@@ -137,7 +138,8 @@ pushHist(Hist *hist, char *ptr)
{ {
HistItem *item; HistItem *item;
if (hist == NULL || hist->list == NULL) if (hist == NULL || hist->list == NULL ||
hist->list->nitem >= HIST_LIST_MAX)
return NULL; return NULL;
item = (HistItem *)newListItem((void *)allocStr(ptr, -1), item = (HistItem *)newListItem((void *)allocStr(ptr, -1),
NULL, (ListItem *)hist->list->last); NULL, (ListItem *)hist->list->last);
@@ -157,7 +159,8 @@ pushHashHist(Hist *hist, char *ptr)
{ {
HistItem *item; HistItem *item;
if (hist == NULL || hist->list == NULL) if (hist == NULL || hist->list == NULL ||
hist->list->nitem >= HIST_LIST_MAX)
return NULL; return NULL;
item = getHashHist(hist, ptr); item = getHashHist(hist, ptr);
if (item) { if (item) {

View File

@@ -5,6 +5,7 @@
#include "textlist.h" #include "textlist.h"
#include "hash.h" #include "hash.h"
#define HIST_LIST_MAX GENERAL_LIST_MAX
#define HIST_HASH_SIZE 127 #define HIST_HASH_SIZE 127
typedef ListItem HistItem; typedef ListItem HistItem;

View File

@@ -30,7 +30,7 @@ void
pushValue(GeneralList *tl, void *s) pushValue(GeneralList *tl, void *s)
{ {
ListItem *it; ListItem *it;
if (s == NULL) if (s == NULL || tl == NULL || tl->nitem >= GENERAL_LIST_MAX)
return; return;
it = newListItem(s, NULL, tl->last); it = newListItem(s, NULL, tl->last);
if (tl->first == NULL) { if (tl->first == NULL) {
@@ -99,6 +99,9 @@ appendGeneralList(GeneralList *tl, GeneralList *tl2)
if (tl && tl2) { if (tl && tl2) {
if (tl2->first) { if (tl2->first) {
if (tl->last) { if (tl->last) {
if (tl->nitem + tl2->nitem > GENERAL_LIST_MAX) {
return tl;
}
tl->last->next = tl2->first; tl->last->next = tl2->first;
tl2->first->prev = tl->last; tl2->first->prev = tl->last;
tl->last = tl2->last; tl->last = tl2->last;

View File

@@ -2,6 +2,8 @@
#ifndef TEXTLIST_H #ifndef TEXTLIST_H
#define TEXTLIST_H #define TEXTLIST_H
#include "Str.h" #include "Str.h"
#include <limits.h>
#define GENERAL_LIST_MAX (INT_MAX / 32)
/* General doubly linked list */ /* General doubly linked list */
@@ -14,7 +16,7 @@ typedef struct _listitem {
typedef struct _generallist { typedef struct _generallist {
ListItem *first; ListItem *first;
ListItem *last; ListItem *last;
short nitem; int nitem;
} GeneralList; } GeneralList;
extern ListItem *newListItem(void *s, ListItem *n, ListItem *p); extern ListItem *newListItem(void *s, ListItem *n, ListItem *p);
@@ -36,7 +38,7 @@ typedef struct _textlistitem {
typedef struct _textlist { typedef struct _textlist {
TextListItem *first; TextListItem *first;
TextListItem *last; TextListItem *last;
short nitem; int nitem;
} TextList; } TextList;
#define newTextList() ((TextList *)newGeneralList()) #define newTextList() ((TextList *)newGeneralList())
@@ -50,7 +52,7 @@ typedef struct _textlist {
typedef struct _TextLine { typedef struct _TextLine {
Str line; Str line;
short pos; int pos;
} TextLine; } TextLine;
typedef struct _textlinelistitem { typedef struct _textlinelistitem {
@@ -62,7 +64,7 @@ typedef struct _textlinelistitem {
typedef struct _textlinelist { typedef struct _textlinelist {
TextLineListItem *first; TextLineListItem *first;
TextLineListItem *last; TextLineListItem *last;
short nitem; int nitem;
} TextLineList; } TextLineList;
extern TextLine *newTextLine(Str line, int pos); extern TextLine *newTextLine(Str line, int pos);