Fossil SCM
Fix a potential division-by-zero in Pikchr.
Commit
bee7418f07591f50393956a3dff499036eb736268d8504fdb5f5c5d5d144412b
Parent
58fb007eb8deed5…
1 file changed
+10
-6
+10
-6
| --- src/pikchr.c | ||
| +++ src/pikchr.c | ||
| @@ -348,11 +348,11 @@ | ||
| 348 | 348 | unsigned int nOut; /* Bytes written to zOut[] so far */ |
| 349 | 349 | unsigned int nOutAlloc; /* Space allocated to zOut[] */ |
| 350 | 350 | unsigned char eDir; /* Current direction */ |
| 351 | 351 | unsigned int mFlags; /* Flags passed to pikchr() */ |
| 352 | 352 | PObj *cur; /* Object under construction */ |
| 353 | - PObj *lastRef; /* Last object references by "place" */ | |
| 353 | + PObj *lastRef; /* Last object references by name */ | |
| 354 | 354 | PList *list; /* Object list under construction */ |
| 355 | 355 | PMacro *pMacros; /* List of all defined macros */ |
| 356 | 356 | PVar *pVar; /* Application-defined variables */ |
| 357 | 357 | PBox bbox; /* Bounding box around all statements */ |
| 358 | 358 | /* Cache of layout values. <=0.0 for unknown... */ |
| @@ -3816,11 +3816,11 @@ | ||
| 3816 | 3816 | static PPoint circleChop(Pik *p, PObj *pObj, PPoint *pPt){ |
| 3817 | 3817 | PPoint chop; |
| 3818 | 3818 | PNum dx = pPt->x - pObj->ptAt.x; |
| 3819 | 3819 | PNum dy = pPt->y - pObj->ptAt.y; |
| 3820 | 3820 | PNum dist = hypot(dx,dy); |
| 3821 | - if( dist<pObj->rad ) return pObj->ptAt; | |
| 3821 | + if( dist<pObj->rad || dist<=0 ) return pObj->ptAt; | |
| 3822 | 3822 | chop.x = pObj->ptAt.x + dx*pObj->rad/dist; |
| 3823 | 3823 | chop.y = pObj->ptAt.y + dy*pObj->rad/dist; |
| 3824 | 3824 | UNUSED_PARAMETER(p); |
| 3825 | 3825 | return chop; |
| 3826 | 3826 | } |
| @@ -6708,13 +6708,17 @@ | ||
| 6708 | 6708 | } |
| 6709 | 6709 | |
| 6710 | 6710 | /* |
| 6711 | 6711 | ** There is a line traveling from pFrom to pTo. |
| 6712 | 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. | |
| 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. | |
| 6716 | 6720 | */ |
| 6717 | 6721 | static void pik_autochop(Pik *p, PPoint *pFrom, PPoint *pTo, PObj *pObj){ |
| 6718 | 6722 | if( pObj==0 || pObj->type->xChop==0 ){ |
| 6719 | 6723 | pObj = pik_find_chopper(p->list, pTo, pFrom); |
| 6720 | 6724 | } |
| @@ -8077,6 +8081,6 @@ | ||
| 8077 | 8081 | |
| 8078 | 8082 | |
| 8079 | 8083 | #endif /* PIKCHR_TCL */ |
| 8080 | 8084 | |
| 8081 | 8085 | |
| 8082 | -#line 8107 "pikchr.c" | |
| 8086 | +#line 8111 "pikchr.c" | |
| 8083 | 8087 |
| --- 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 |