Skip to content

Commit

Permalink
Xic/WRspice/Mozy: fixes to avoid seg faults from gcc-8.2 (Fedora 29).
Browse files Browse the repository at this point in the history
This compiler seg faults when a method is called on a null object.
Once upon a time this was perfectly fine, and one could test the
'this' pointer in the called function for a null object.  Xic and
WRspice used this "feature" a lot, and have had to be updated as a
consequence.  Somehow two instances of un-updated code didn't fault
until this compiler.
  • Loading branch information
wrcad committed Feb 28, 2019
1 parent 6f2fcc4 commit 0cc7459
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 41 deletions.
22 changes: 16 additions & 6 deletions mozy/include/help/help_topic.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct HLPtopList
{
HLPtopList(const char *d, const char *kw, HLPtopic *t, HLPtopList *n)
{
next = n;
tl_next = n;
tl_keyword = lstring::copy(kw);
tl_description = lstring::copy(d);
tl_buttontext = 0;
Expand All @@ -66,18 +66,26 @@ struct HLPtopList
delete [] tl_description;
}

HLPtopList *next() { return (tl_next); }
const char *keyword() const { return (tl_keyword); }
const char *description() const { return (tl_description); }
const char *buttontext() const { return (tl_buttontext); }

void set_buttontext(const char *t) { tl_buttontext = t; }

static void destroy(HLPtopList *tl)
{
while (tl) {
HLPtopList *tx = tl;
tl = tl->next;
tl = tl->tl_next;
delete tx;
}
}

HLPtopList *sort();
static HLPtopList *sort(HLPtopList*);

HLPtopList *next;
private:
HLPtopList *tl_next;
char *tl_keyword;
char *tl_description;
const char *tl_buttontext;
Expand Down Expand Up @@ -196,12 +204,14 @@ struct HLPtopic
HLPtopList *subtopics() { return (tp_subtopics); }
void add_subtopic(const char *t, const char *w)
{ tp_subtopics = new HLPtopList(t, w, this, tp_subtopics); }
void sort_subtopics() { tp_subtopics = tp_subtopics->sort(); }
void sort_subtopics()
{ tp_subtopics = HLPtopList::sort(tp_subtopics); }

HLPtopList *seealso() { return (tp_seealso); }
void add_seealso(const char *t, const char *w)
{ tp_seealso = new HLPtopList(t, w, this, tp_seealso); }
void sort_seealso() { tp_seealso = tp_seealso->sort(); }
void sort_seealso()
{ tp_seealso = HLPtopList::sort(tp_seealso); }

GRwbag *context() { return (tp_context); }
void set_context(GRwbag *c) { tp_context = c; }
Expand Down
2 changes: 1 addition & 1 deletion mozy/src/help/help_read.cc
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ cHelp::search(const char *target)
top->sort_seealso();
int i;
HLPtopList *tl;
for (i = 0, tl = top->seealso(); tl; i++, tl = tl->next) ;
for (i = 0, tl = top->seealso(); tl; i++, tl = tl->next()) ;
sprintf(buf, "Keyword search for %s : %d entries found.", target, i);
top->set_words(new HLPwords(buf, 0));
top->register_word(buf);
Expand Down
44 changes: 22 additions & 22 deletions mozy/src/help/help_topic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -492,23 +492,23 @@ HLPtopic::load_text()
if (!tp_show_plain) {
if (tp_subtopics) {
lstr.add("<H3>Subtopics</H3>\n");
for (HLPtopList *tl = tp_subtopics; tl; tl = tl->next) {
tl->tl_buttontext = tl->tl_description;
if (!tl->tl_buttontext)
tl->tl_buttontext = "<unknown>";
for (HLPtopList *tl = tp_subtopics; tl; tl = tl->next()) {
tl->set_buttontext(tl->description());
if (!tl->buttontext())
tl->set_buttontext("<unknown>");
sprintf(tbuf, "<A HREF=\"%s\">%s</A><BR>\n",
tl->tl_keyword, tl->tl_buttontext);
tl->keyword(), tl->buttontext());
lstr.add(tbuf);
}
}
if (tp_seealso) {
lstr.add("<H3>References</H3>\n");
for (HLPtopList *tl = tp_seealso; tl; tl = tl->next) {
tl->tl_buttontext = tl->tl_description;
if (!tl->tl_buttontext)
tl->tl_buttontext = "<unknown>";
for (HLPtopList *tl = tp_seealso; tl; tl = tl->next()) {
tl->set_buttontext(tl->description());
if (!tl->buttontext())
tl->set_buttontext("<unknown>");
sprintf(tbuf, "<A HREF=\"%s\">%s</A><BR>\n",
tl->tl_keyword, tl->tl_buttontext);
tl->keyword(), tl->buttontext());
lstr.add(tbuf);
}
}
Expand Down Expand Up @@ -558,11 +558,11 @@ namespace {
// Strip HTML tags from the beginning of the string, return the first
// text.
//
inline char *
striptag(char *s)
inline const char *
striptag(const char *s)
{
while (*s == '<') {
char *t = s + 1;
const char *t = s + 1;
while (*t && *t != '>')
t++;
if (!*t)
Expand All @@ -575,8 +575,8 @@ namespace {
inline bool
sortcmp(const HLPtopList *tlp1, const HLPtopList *tlp2)
{
char *s1 = tlp1->tl_description;
char *s2 = tlp2->tl_description;
const char *s1 = tlp1->description();
const char *s2 = tlp2->description();
s1 = striptag(s1);
s2 = striptag(s2);
while (*s1 && *s2) {
Expand Down Expand Up @@ -606,23 +606,23 @@ namespace {


HLPtopList *
HLPtopList::sort()
HLPtopList::sort(HLPtopList *list)
{
int num;
HLPtopList *tl;
for (num = 0, tl = this; tl; num++, tl = tl->next) ;
int num;
for (tl = list, num = 0; tl; num++, tl = tl->tl_next) ;
if (num < 2)
return (this);
return (list);

HLPtopList **vec = new HLPtopList*[num];
int i;
for (tl = this, i = 0; tl; tl = tl->next, i++)
for (tl = list, i = 0; tl; tl = tl->tl_next, i++)
vec[i] = tl;
std::sort(vec, vec + num, sortcmp);
tl = vec[0];
for (i = 0; i < num - 1; i++)
vec[i]->next = vec[i + 1];
vec[i]->next = 0;
vec[i]->tl_next = vec[i + 1];
vec[i]->tl_next = 0;
delete [] vec;
return (tl);
}
Expand Down
6 changes: 3 additions & 3 deletions xic/include/pushpop.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct ContextDesc

void purge(const CDs*, const CDl*);
ContextDesc *purge(const CDs*, const CDo*);
void clear();
static void clear(ContextDesc*);

int level()
{
Expand Down Expand Up @@ -119,8 +119,8 @@ struct CXstate

~CXstate()
{
context->clear();
context_history->clear();
ContextDesc::clear(context);
ContextDesc::clear(context_history);
}

CDcellName cellname;
Expand Down
18 changes: 9 additions & 9 deletions xic/src/main/pushpop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ ContextDesc::purge(const CDs *sd, const CDo *od)
cp->cNext = 0;
else
c0 = 0;
cx->clear();
ContextDesc::clear(cx);
return (c0);
}
if (cx->cState)
Expand All @@ -124,10 +124,10 @@ ContextDesc::purge(const CDs *sd, const CDo *od)
}


// Static function.
void
ContextDesc::clear()
ContextDesc::clear(ContextDesc *c)
{
ContextDesc *c = this;
while (c) {
ContextDesc *cn = c->cNext;
delete c;
Expand Down Expand Up @@ -280,7 +280,7 @@ cPushPop::PushContext(const CDc *cdesc, unsigned int xind, unsigned int yind)
msdesc = cdesc->masterCell();
if (!msdesc)
return;
context_history->clear(); // clear history
ContextDesc::clear(context_history); // clear history
context_history = 0;
context = new ContextDesc(cdesc, xind, yind);

Expand Down Expand Up @@ -434,7 +434,7 @@ cPushPop::ClearContext(bool skip_commit)
while (context)
PopContext();
no_display = false;
context_history->clear();
ContextDesc::clear(context_history);
context_history = 0;
if (!skip_commit)
XM()->CommitCell();
Expand All @@ -452,9 +452,9 @@ cPushPop::ClearContext(bool skip_commit)
void
cPushPop::ClearLists()
{
context->clear();
ContextDesc::clear(context);
context = 0;
context_history->clear();
ContextDesc::clear(context_history);
context_history = 0;
}

Expand Down Expand Up @@ -490,9 +490,9 @@ cPushPop::PopState()
void
cPushPop::PushState(CXstate *ecx)
{
context->clear();
ContextDesc::clear(context);
context = 0;
context_history->clear();
ContextDesc::clear(context_history);
context_history = 0;

if (ecx) {
Expand Down

0 comments on commit 0cc7459

Please sign in to comment.