From: Michael D. Lowis Date: Wed, 4 Apr 2018 17:07:52 +0000 (-0400) Subject: fixed bugs detected by scan-build X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=8ba78628c0b8e6f64a9fd9d45f0698b21ac8cde5;p=projs%2Ftide.git fixed bugs detected by scan-build --- diff --git a/lib/buf.c b/lib/buf.c index d7cd6fa..130f336 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -34,8 +34,9 @@ void buf_init(Buf* buf) { } void buf_load(Buf* buf, char* path) { + if (!path) return; /* process the file path and address */ - if (path && path[0] == '.' && path[1] == '/') + if (path[0] == '.' && path[1] == '/') path += 2; buf->path = stringdup(path); @@ -76,7 +77,7 @@ void buf_save(Buf* buf) { buf_putc(buf, '\n', &(Sel){ .end = buf_end(buf)-1 }); char* wptr; - long fd, nwrite, towrite; + long fd, nwrite = 0, towrite = 0; if (buf->path && (fd = open(buf->path, O_WRONLY|O_CREAT, 0644)) >= 0) { /* write the chunk before the gap */ wptr = buf->bufstart, towrite = (buf->gapstart - buf->bufstart); diff --git a/lib/x11.c b/lib/x11.c index 08ddbcb..e0577da 100644 --- a/lib/x11.c +++ b/lib/x11.c @@ -45,19 +45,19 @@ static void xresize(XEvent* e); static void xexpose(XEvent* e); static void (*EventHandlers[LASTEvent])(XEvent*) = { - [FocusIn] = xfocus, - [FocusOut] = xfocus, - [KeyPress] = xkeypress, - [ButtonPress] = xbtnpress, - [ButtonRelease] = xbtnrelease, - [MotionNotify] = xbtnmotion, - [SelectionClear] = xselclear, - [SelectionNotify] = xselnotify, - [SelectionRequest] = xselrequest, - [PropertyNotify] = xpropnotify, - [ClientMessage] = xclientmsg, - [ConfigureNotify] = xresize, - [Expose] = xexpose, + [FocusIn] = xfocus, + [FocusOut] = xfocus, + [KeyPress] = xkeypress, + [ButtonPress] = xbtnpress, + [ButtonRelease] = xbtnrelease, + [MotionNotify] = xbtnmotion, + [SelectionClear] = xselclear, + [SelectionNotify] = xselnotify, + [SelectionRequest] = xselrequest, + [PropertyNotify] = xpropnotify, + [ClientMessage] = xclientmsg, + [ConfigureNotify] = xresize, + [Expose] = xexpose, }; /******************************************************************************/ @@ -483,19 +483,19 @@ static void xupdate(Job* job) { //draw_scroll(); /* flush to the server */ XCopyArea(X.display, X.pixmap, X.self, X.gc, 0, 0, X.width, X.height, 0, 0); - XFlush(X.display); + XFlush(X.display); } static void xfocus(XEvent* e) { if (X.xic) (e->type == FocusIn ? XSetICFocus : XUnsetICFocus)(X.xic); - Buf* buf = win_buf(EDIT); +// Buf* buf = win_buf(EDIT); // if (buf->path && buf->modtime != modtime(buf->path)) // view_append(win_view(TAGS), "File modified externally: Get {Put }"); } static void xkeypress(XEvent* e) { - win_setregion(getregion(e->xkey.x, e->xkey.y)); + win_setregion(getregion(e->xkey.x, e->xkey.y)); uint32_t key = getkey(e); if (key == RUNE_ERR) return; KeyBtnState = e->xkey.state, LastKey = key; @@ -529,7 +529,7 @@ static void xbtnrelease(XEvent* e) { static void xbtnmotion(XEvent* e) { if ((KeyBtnState & 0x1f00) == 0) - win_setregion(getregion(e->xbutton.x, e->xbutton.y)); + win_setregion(getregion(e->xbutton.x, e->xbutton.y)); KeyBtnState = e->xbutton.state; int x = e->xbutton.x, y = e->xbutton.y; if (x < Regions[Focused].x) x = Regions[Focused].x; @@ -658,7 +658,7 @@ static uint32_t getkey(XEvent* e) { static void mouse_click(int btn, bool pressed, int x, int y) { if ((KeyBtnState & 0x1f00) == 0) - win_setregion(getregion(x, y)); + win_setregion(getregion(x, y)); WinRegion id = getregion(x, y); if (id == FOCUSED && x < Regions[Focused].x) x = Regions[Focused].x, id = getregion(x, y); @@ -770,9 +770,6 @@ static void draw_view(int i, int width, int height, int bg, int fg, int csr, int } static void redraw(int width, int height) { - size_t fheight = x11_font_height(CurrFont); - size_t fwidth = x11_font_width(CurrFont); - layout(width, height); int clrtagnor = (TagsBg << 8 | TagsFg); int clrtagsel = (TagsSel << 8 | TagsFg);