Commit 2ab1e96d authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Fix for abort when dragging an unknown filetype to Draw, and a bogus error message

Various places in Draw were making an error block (via makmsg or retmsg macros) from a cast pointer using the msg part of RISC_OSLib. However, as RISC_OSLib caches the messages file and returns direct pointers to it, the resulting error blocks would often not be word aligned, leading to an abort when the Wimp tries to copy it for the Wimp_ReportError.
In turn, the abort would be reported as unhelpful "wimpt1" message because the signal handler was looking it up in the application messages, not the default RISC_OSLib messages.
Draw.c:
New function top copy the msg to a word aligned static struct.
Fix signal handler to use msgs_default_control_block() so that "wimpt1" can be found.
Draw.h/others:
Replace makmsg and retmsg with calls to the new aligning function.

Tested by dragging a GIF and a BMP to Draw, and it no longer aborts.

Version 1.28. Tagged as 'Draw-1_28'
parent 5e561b45
......@@ -11,13 +11,13 @@
GBLS Module_HelpVersion
GBLS Module_ComponentName
GBLS Module_ComponentPath
Module_MajorVersion SETS "1.27"
Module_Version SETA 127
Module_MajorVersion SETS "1.28"
Module_Version SETA 128
Module_MinorVersion SETS ""
Module_Date SETS "24 Mar 2015"
Module_ApplicationDate SETS "24-Mar-15"
Module_Date SETS "04 Dec 2015"
Module_ApplicationDate SETS "04-Dec-15"
Module_ComponentName SETS "Draw"
Module_ComponentPath SETS "castle/RiscOS/Sources/Apps/Draw"
Module_FullVersion SETS "1.27"
Module_HelpVersion SETS "1.27 (24 Mar 2015)"
Module_FullVersion SETS "1.28"
Module_HelpVersion SETS "1.28 (04 Dec 2015)"
END
/* (1.27)
/* (1.28)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 1.27
#define Module_MajorVersion_CMHG 1.28
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 24 Mar 2015
#define Module_Date_CMHG 04 Dec 2015
#define Module_MajorVersion "1.27"
#define Module_Version 127
#define Module_MajorVersion "1.28"
#define Module_Version 128
#define Module_MinorVersion ""
#define Module_Date "24 Mar 2015"
#define Module_Date "04 Dec 2015"
#define Module_ApplicationDate "24-Mar-15"
#define Module_ApplicationDate "04-Dec-15"
#define Module_ComponentName "Draw"
#define Module_ComponentPath "castle/RiscOS/Sources/Apps/Draw"
#define Module_FullVersion "1.27"
#define Module_HelpVersion "1.27 (24 Mar 2015)"
#define Module_LibraryVersionInfo "1:27"
#define Module_FullVersion "1.28"
#define Module_HelpVersion "1.28 (04 Dec 2015)"
#define Module_LibraryVersionInfo "1:28"
......@@ -543,6 +543,15 @@ void draw_reset_gchar (void)
}
}
/*Produce a correctly word aligned error from a messages file token*/
os_error *draw_make_oserror (const char *token)
{ static os_error block;
/* N.B. prefix messages with #### to fake error number field */
memcpy (&block, msgs_lookup ((char *) token), sizeof (block));
return █
}
/*Make origin, typically from a wimp_openstr*/
static void make_origin (draw_objcoord *to, wimp_box *box, int *scroll)
......@@ -1572,7 +1581,7 @@ static os_error *load_file (diagrec *diag, viewrec *vuue, draw_objcoord *pt,
default:
#if REJECTUNKNOWNFILETYPES
return makmsg ("DrawCL");
return draw_make_oserror ("DrawCL");
#endif
break;
......@@ -1604,7 +1613,7 @@ static os_error *load_file (diagrec *diag, viewrec *vuue, draw_objcoord *pt,
default:
#if REJECTUNKNOWNFILETYPES
if (!dataopen) return makmsg ("DrawCL");
if (!dataopen) return draw_make_oserror ("DrawCL");
#endif
break;
}
......@@ -2737,7 +2746,7 @@ int main (int argc, char **argv)
os_error errblk = {0, "wimpt1"};
regs.r[0] = (int)&errblk;
regs.r[1] = (int)msgs_main_control_block ();
regs.r[1] = (int)msgs_default_control_block ();
regs.r[2] = NULL;
regs.r[3] = 0;
err = os_swix (MessageTrans_ErrorLookup, &regs);
......@@ -2973,7 +2982,7 @@ static os_error *draw_createblank (int size, diagrec **diagp,
/*Claim a small (non shifting) block, to hold pointers to our*/
/*main dBase, misc workspace & filename*/
if ((diag = (diagrec *) Alloc (sizeof (diagrec))) == NULL)
retmsg ("DrawNR"); /*Return error*/
return draw_make_oserror ("DrawNR"); /*Return error*/
ftracef1 ("draw_createblank: allocated diag: 0x%X\n", diag);
/*diag now holds a pointer to a block in 'C's heap, dispose of this*/
......@@ -2983,20 +2992,20 @@ static os_error *draw_createblank (int size, diagrec **diagp,
ftracef1 ("draw_createblank: claiming %d bytes of paper\n", size);
if (FLEX_ALLOC ((flex_ptr) &diag->misc, sizeof (draw_diagstr)) == NULL)
{ Free (diag);
retmsg ("DrawNR");
return draw_make_oserror ("DrawNR");
}
if (FLEX_ALLOC ((flex_ptr) &diag->paper, size) == NULL)
{ FLEX_FREE ((flex_ptr) &diag->misc); /*free 1st block*/
Free (diag);
retmsg ("DrawNR");
return draw_make_oserror ("DrawNR");
}
if ((diag->undo = draw_undo_new ()) == NULL)
{ FLEX_FREE ((flex_ptr) &diag->paper);
FLEX_FREE ((flex_ptr) &diag->misc); /*free 1st block*/
Free (diag);
retmsg ("DrawNR");
return draw_make_oserror ("DrawNR");
}
draw_undo_setbufsize (diag, opt->undo_size);
......@@ -3159,12 +3168,12 @@ static os_error *draw_createview (diagrec *diag, viewrec **vuuep)
*vuuep = 0; /*incase Alloc fails*/
if ((vuue = (viewrec *) Alloc (sizeof (viewrec))) == NULL)
retmsg ("DrawNR") /*Return error*/
return draw_make_oserror ("DrawNR"); /*Return error*/
/*Allocate space for title*/
if ((title = Alloc (TITLEBUFMAX)) == NULL)
{ Free (vuue);
retmsg ("DrawNR")
return draw_make_oserror ("DrawNR");
}
*title = 0;
......
......@@ -907,9 +907,8 @@ static os_error *do_objtrfmtext_system (draw_objptr hdrptr,
len = strlen (hdrptr.trfmtextp->text);
size_of_area = 10*1024; /*!!!*/
if ((area = Alloc (size_of_area)) == NULL)
{ ftracef1 ("-> \"%s\"\n",
((os_error *) msgs_lookup ("DrawNR"))->errmess);
return (os_error *) msgs_lookup ("DrawNR");
{ ftracef1 ("-> out of memory\n");
return draw_make_oserror ("DrawNR");
}
ftracef0 ("do_objtrfmtext_system: initialise sprite area\n");
......@@ -1203,7 +1202,7 @@ static os_error *do_objtrfmtext (draw_objptr hdrptr, draw_objcoord *org)
/*Make a buffer big enough*/
if ((misc_data = Alloc (reg_set1.r [4])) == NULL)
{ (void) font_lose (fonth);
return (os_error *) msgs_lookup ("DrawNR");
return draw_make_oserror ("DrawNR");
}
/*Fill in the buffer*/
......@@ -1227,7 +1226,7 @@ static os_error *do_objtrfmtext (draw_objptr hdrptr, draw_objcoord *org)
if ((buf = Alloc (3 + strlen (hdrptr.trfmtextp->text) + 1))
== NULL)
{ (void) font_lose (fonth);
return (os_error *) msgs_lookup ("DrawNR");
return draw_make_oserror ("DrawNR");
}
/*Fill in the string*/
......
......@@ -88,7 +88,7 @@ os_error *draw_obj_checkspace(diagrec *diag, int needed)
diag->misc->bufferlimit += shortfall;
}
else
retmsg("DrawNR");
return draw_make_oserror("DrawNR");
}
return 0;
......
......@@ -344,7 +344,7 @@ os_error *draw_print_to_file (diagrec *diag, int file, BOOL illustration)
draw_obj_bound_all (diag, &pictureBB);
if (pictureBB.x0 > pictureBB.x1 || pictureBB.y0 > pictureBB.y1)
{ error = (os_error *) msgs_lookup ("Print2");
{ error = draw_make_oserror ("Print2");
goto finish;
}
......@@ -483,7 +483,7 @@ os_error *draw_print_printall (diagrec *diag)
goto finish;
ftracef0 ("OS_Find returned successfully\n");
if (blk.r [0] == 0)
{ error = (os_error *) msgs_lookup ("Print3");
{ error = draw_make_oserror ("Print3");
goto finish;
}
ftracef0 ("OS_Find returned a valid handle\n");
......@@ -526,7 +526,7 @@ os_error *draw_print_queue (diagrec *diag, int copies)
/*Check that there is a printer.*/
if (draw_printer_name () == NULL)
return (os_error *) msgs_lookup ("Print1");
return draw_make_oserror ("Print1");
print_copies = copies;
......@@ -540,7 +540,7 @@ os_error *draw_print_queue (diagrec *diag, int copies)
diag->misc->solidlimit - diag->misc->solidstart,
&draw_file_file_saveall, &draw_file_ram_saveall, &draw_file_printall,
diag))
retmsg ("Print3");
return draw_make_oserror ("Print3");
return NULL;
}
......
......@@ -153,7 +153,7 @@ os_error *draw_select_checkspace (void)
/*array full, try to extend*/
if (FLEX_EXTEND ((flex_ptr) &draw_selection, newsize) == 0)
{ ftracef0 ("draw_select_checkspace: extending draw_selection FAILED\n");
retmsg ("DrawR3");
return draw_make_oserror ("DrawR3");
}
ftracef1 ("draw_select_checkspace: draw_selection 0x%X\n",
......@@ -2551,7 +2551,7 @@ static os_error *Convert_Text_Line_To_Paths (diagrec *diag,
if ((text_line_ptr.objhdrp->tag == draw_OBJTEXT?
text_line_ptr.textp->textstyle.fontref:
text_line_ptr.trfmtextp->textstyle.fontref) == NULL)
return (os_error *) msgs_lookup ("DrawT");
return draw_make_oserror ("DrawT");
ftracef0 ("turn off system font output\n"); /*JRC 1 Feb 1990*/
(void) bbc_vdu (bbc_DisableVDU);
......
......@@ -167,12 +167,6 @@ don't work at large zoom factors.*/
#define tbi_elli 7
#define tbi_select 8
/* N.B. prefix messages with #### to fake */
/* error number field */
#define makmsg(A) ((os_error *) (msgs_lookup (A)))
#define retmsg(A) {return makmsg (A);}
#define MAX(a, b) ((a) > (b)? (a): (b))
#define MIN(a, b) ((a) < (b)? (a): (b))
......@@ -1212,9 +1206,12 @@ extern void draw_make_clip(wimp_redrawstr *r, draw_objcoord *org, draw_bboxtyp *
/* Set printer limits from capture box */
extern void draw_set_paper_limits(diagrec *diag, captu_str box);
/* Restet VDU 5 character size after change */
/* Reset VDU 5 character size after change */
extern void draw_reset_gchar(void);
/* Conjure an OS error from a Draw message token */
extern os_error *draw_make_oserror(const char *token);
/*-----------------------------------------------------------------------*/
/* Some of the following functions are actually declared in c.drawAction */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment