From 0ffa79de9d663656b84dda2097498291941a9e98 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 28 Apr 2000 14:42:59 +0000 Subject: [PATCH] Avoid crash when PS file does not exist git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@704 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 6 ++++++ src/insets/figinset.C | 23 +++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 097c239464..d60a82a6bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2000-04-28 Jean-Marc Lasgouttes + + * src/insets/figinset.C (various): Use IsFileReadable() to make + sure that the file actually exist. Relying on ghostscripts errors + is a bad idea since they can lead to X server crashes. + 2000-04-27 Claus Hentschel * intl/loadmsgcat.c (_nl_load_domain): pass O_BINARY as flag to diff --git a/src/insets/figinset.C b/src/insets/figinset.C index 5729de4a68..c892ac2007 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -775,7 +775,8 @@ figdata * getfigdata(int wid, int hgh, string const & fname, { /* first search for an exact match with fname and width/height */ - if (fname.empty()) return 0; + if (fname.empty() || !IsFileReadable(fname)) + return 0; for (bitmaps_type::iterator it = bitmaps.begin(); it != bitmaps.end(); ++it) { @@ -1062,10 +1063,15 @@ void InsetFig::draw(Painter & pain, LyXFont const & f, if (figure && figure->data) { if (figure->data->broken) msg = _("[render error]"); else if (figure->data->reading) msg = _("[rendering ... ]"); - } else - if (fname.empty()) msg = _("[no file]"); - else if ((flags & 3) == 0) msg = _("[not displayed]"); - else if (lyxrc.ps_command.empty()) msg = _("[no ghostscript]"); + } + else if (fname.empty()) + msg = _("[no file]"); + else if (!IsFileReadable(fname)) + msg = _("[bad file name]"); + else if ((flags & 3) == 0) + msg = _("[not displayed]"); + else if (lyxrc.ps_command.empty()) + msg = _("[no ghostscript]"); if (!msg) msg = _("[unknown error]"); @@ -1299,7 +1305,8 @@ Inset * InsetFig::Clone() const tmp->pswid = pswid; tmp->pshgh = pshgh; tmp->fname = fname; - if (!fname.empty() && (flags & 3) && !lyxrc.ps_command.empty() + if (!fname.empty() && IsFileReadable(fname) + && (flags & 3) && !lyxrc.ps_command.empty() && lyxrc.use_gui) { // do not display if there is // "do not display" chosen (Matthias 260696) @@ -1475,7 +1482,7 @@ void InsetFig::Recompute() /* now recompute wid and hgh, and if that is changed, set changed */ /* this depends on chosen size of the picture and its bbox */ // This will be redone in 0.13 ... (hen) - if (!fname.empty()) { + if (!fname.empty() && IsFileReadable(fname)) { // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */ newx = frame_wid; @@ -1554,7 +1561,7 @@ void InsetFig::Recompute() figdata * pf = figure->data; // get new data - if (!fname.empty() && (flags & 3) + if (!fname.empty() && IsFileReadable(fname) && (flags & 3) && !lyxrc.ps_command.empty()) { // do not display if there is "do not display" // chosen (Matthias 260696) -- 2.39.5