From 6a0d21acca616aa4cf11468e3dc6f1c052e1d94f Mon Sep 17 00:00:00 2001 From: ppatience0 Date: Mon, 27 May 2013 00:26:19 -0400 Subject: [PATCH] mothra: clicking on the url scroll bar, snarfing, or saving a hit when no urls have been loaded (right after running mothra) would crash. this was due to use of w->url and selection when they are actually nil. to fix this, make genwww return 0 if w->url is nil and output an error message when attempting to access selection if it's nil. the problem with the w->url fix is that after clicking on the url scroll bar, an empty url history row could be highlighted by clicking on it. fix this by making sure lp->lo is not less than zero. --- sys/src/cmd/mothra/libpanel/list.c | 2 +- sys/src/cmd/mothra/mothra.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/sys/src/cmd/mothra/libpanel/list.c b/sys/src/cmd/mothra/libpanel/list.c index fb9b676f7..8f4b0766f 100644 --- a/sys/src/cmd/mothra/libpanel/list.c +++ b/sys/src/cmd/mothra/libpanel/list.c @@ -22,7 +22,7 @@ void pl_listsel(Panel *p, int sel, int on){ Rectangle r; lp=p->data; hi=lp->lo+(lp->listr.max.y-lp->listr.min.y)/font->height; - if(lp->lo<=sel && sellen){ + if(lp->lo>=0 && lp->lo<=sel && sellen){ r=lp->listr; r.min.y+=(sel-lp->lo)*font->height; r.max.y=r.min.y+font->height; diff --git a/sys/src/cmd/mothra/mothra.c b/sys/src/cmd/mothra/mothra.c index d1d06abe3..79e6191d2 100644 --- a/sys/src/cmd/mothra/mothra.c +++ b/sys/src/cmd/mothra/mothra.c @@ -484,6 +484,8 @@ char *genwww(Panel *, int index){ return 0; i = wwwtop-index-1; w = www(i); + if(!w->url) + return 0; if(w->title[0]!='\0'){ w->gottitle=1; snprint(buf, sizeof(buf), "%2d %s", i+1, w->title); @@ -1027,8 +1029,11 @@ void killpix(Www *w){ } void snarf(Panel *p){ if(p==0 || p==cmd){ - plputsnarf(urlstr(selection)); - plsnarf(text); + if(selection){ + plputsnarf(urlstr(selection)); + plsnarf(text); + }else + message("no url selected"); }else plsnarf(p); } @@ -1070,6 +1075,10 @@ void hit3(int button, int item){ paste(plkbfocus); break; case 4: + if(!selection){ + message("no url selected"); + break; + } snprint(name, sizeof(name), "%s/hit.html", home); fd=open(name, OWRITE); if(fd==-1){