Fossil SCM

Fix a potential division-by-zero in Pikchr.

drh 2021-07-18 00:00 trunk
Commit bee7418f07591f50393956a3dff499036eb736268d8504fdb5f5c5d5d144412b
1 file changed +10 -6
+10 -6
--- src/pikchr.c
+++ src/pikchr.c
@@ -348,11 +348,11 @@
348348
unsigned int nOut; /* Bytes written to zOut[] so far */
349349
unsigned int nOutAlloc; /* Space allocated to zOut[] */
350350
unsigned char eDir; /* Current direction */
351351
unsigned int mFlags; /* Flags passed to pikchr() */
352352
PObj *cur; /* Object under construction */
353
- PObj *lastRef; /* Last object references by "place" */
353
+ PObj *lastRef; /* Last object references by name */
354354
PList *list; /* Object list under construction */
355355
PMacro *pMacros; /* List of all defined macros */
356356
PVar *pVar; /* Application-defined variables */
357357
PBox bbox; /* Bounding box around all statements */
358358
/* Cache of layout values. <=0.0 for unknown... */
@@ -3816,11 +3816,11 @@
38163816
static PPoint circleChop(Pik *p, PObj *pObj, PPoint *pPt){
38173817
PPoint chop;
38183818
PNum dx = pPt->x - pObj->ptAt.x;
38193819
PNum dy = pPt->y - pObj->ptAt.y;
38203820
PNum dist = hypot(dx,dy);
3821
- if( dist<pObj->rad ) return pObj->ptAt;
3821
+ if( dist<pObj->rad || dist<=0 ) return pObj->ptAt;
38223822
chop.x = pObj->ptAt.x + dx*pObj->rad/dist;
38233823
chop.y = pObj->ptAt.y + dy*pObj->rad/dist;
38243824
UNUSED_PARAMETER(p);
38253825
return chop;
38263826
}
@@ -6708,13 +6708,17 @@
67086708
}
67096709
67106710
/*
67116711
** There is a line traveling from pFrom to pTo.
67126712
**
6713
-** If point pTo is the exact enter of a choppable object,
6714
-** then adjust pTo by the appropriate amount in the direction
6715
-** of pFrom.
6713
+** If pObj is not null and is a choppable object, then chop at
6714
+** the boundary of pObj - where the line crosses the boundary
6715
+** of pObj.
6716
+**
6717
+** If pObj is NULL or has no xChop method, then search for some
6718
+** other object centered at pTo that is choppable and use it
6719
+** instead.
67166720
*/
67176721
static void pik_autochop(Pik *p, PPoint *pFrom, PPoint *pTo, PObj *pObj){
67186722
if( pObj==0 || pObj->type->xChop==0 ){
67196723
pObj = pik_find_chopper(p->list, pTo, pFrom);
67206724
}
@@ -8077,6 +8081,6 @@
80778081
80788082
80798083
#endif /* PIKCHR_TCL */
80808084
80818085
8082
-#line 8107 "pikchr.c"
8086
+#line 8111 "pikchr.c"
80838087
--- src/pikchr.c
+++ src/pikchr.c
@@ -348,11 +348,11 @@
348 unsigned int nOut; /* Bytes written to zOut[] so far */
349 unsigned int nOutAlloc; /* Space allocated to zOut[] */
350 unsigned char eDir; /* Current direction */
351 unsigned int mFlags; /* Flags passed to pikchr() */
352 PObj *cur; /* Object under construction */
353 PObj *lastRef; /* Last object references by "place" */
354 PList *list; /* Object list under construction */
355 PMacro *pMacros; /* List of all defined macros */
356 PVar *pVar; /* Application-defined variables */
357 PBox bbox; /* Bounding box around all statements */
358 /* Cache of layout values. <=0.0 for unknown... */
@@ -3816,11 +3816,11 @@
3816 static PPoint circleChop(Pik *p, PObj *pObj, PPoint *pPt){
3817 PPoint chop;
3818 PNum dx = pPt->x - pObj->ptAt.x;
3819 PNum dy = pPt->y - pObj->ptAt.y;
3820 PNum dist = hypot(dx,dy);
3821 if( dist<pObj->rad ) return pObj->ptAt;
3822 chop.x = pObj->ptAt.x + dx*pObj->rad/dist;
3823 chop.y = pObj->ptAt.y + dy*pObj->rad/dist;
3824 UNUSED_PARAMETER(p);
3825 return chop;
3826 }
@@ -6708,13 +6708,17 @@
6708 }
6709
6710 /*
6711 ** There is a line traveling from pFrom to pTo.
6712 **
6713 ** If point pTo is the exact enter of a choppable object,
6714 ** then adjust pTo by the appropriate amount in the direction
6715 ** of pFrom.
 
 
 
 
6716 */
6717 static void pik_autochop(Pik *p, PPoint *pFrom, PPoint *pTo, PObj *pObj){
6718 if( pObj==0 || pObj->type->xChop==0 ){
6719 pObj = pik_find_chopper(p->list, pTo, pFrom);
6720 }
@@ -8077,6 +8081,6 @@
8077
8078
8079 #endif /* PIKCHR_TCL */
8080
8081
8082 #line 8107 "pikchr.c"
8083
--- src/pikchr.c
+++ src/pikchr.c
@@ -348,11 +348,11 @@
348 unsigned int nOut; /* Bytes written to zOut[] so far */
349 unsigned int nOutAlloc; /* Space allocated to zOut[] */
350 unsigned char eDir; /* Current direction */
351 unsigned int mFlags; /* Flags passed to pikchr() */
352 PObj *cur; /* Object under construction */
353 PObj *lastRef; /* Last object references by name */
354 PList *list; /* Object list under construction */
355 PMacro *pMacros; /* List of all defined macros */
356 PVar *pVar; /* Application-defined variables */
357 PBox bbox; /* Bounding box around all statements */
358 /* Cache of layout values. <=0.0 for unknown... */
@@ -3816,11 +3816,11 @@
3816 static PPoint circleChop(Pik *p, PObj *pObj, PPoint *pPt){
3817 PPoint chop;
3818 PNum dx = pPt->x - pObj->ptAt.x;
3819 PNum dy = pPt->y - pObj->ptAt.y;
3820 PNum dist = hypot(dx,dy);
3821 if( dist<pObj->rad || dist<=0 ) return pObj->ptAt;
3822 chop.x = pObj->ptAt.x + dx*pObj->rad/dist;
3823 chop.y = pObj->ptAt.y + dy*pObj->rad/dist;
3824 UNUSED_PARAMETER(p);
3825 return chop;
3826 }
@@ -6708,13 +6708,17 @@
6708 }
6709
6710 /*
6711 ** There is a line traveling from pFrom to pTo.
6712 **
6713 ** If pObj is not null and is a choppable object, then chop at
6714 ** the boundary of pObj - where the line crosses the boundary
6715 ** of pObj.
6716 **
6717 ** If pObj is NULL or has no xChop method, then search for some
6718 ** other object centered at pTo that is choppable and use it
6719 ** instead.
6720 */
6721 static void pik_autochop(Pik *p, PPoint *pFrom, PPoint *pTo, PObj *pObj){
6722 if( pObj==0 || pObj->type->xChop==0 ){
6723 pObj = pik_find_chopper(p->list, pTo, pFrom);
6724 }
@@ -8077,6 +8081,6 @@
8081
8082
8083 #endif /* PIKCHR_TCL */
8084
8085
8086 #line 8111 "pikchr.c"
8087

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button