commit f21fec9355ca160ca4f0e8d635e0986bbe3365ed
parent 96d0cdaa7b45c953d14eddaedd9a527d91288de0
Author: Claudio Alessi <smoppy@gmail.com>
Date: Thu, 14 Apr 2016 22:42:27 +0200
Improve viewtable_show().
Also fix a memory leak due to an free() call inadvertitely removed.
Diffstat:
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/myadm.c b/myadm.c
@@ -653,7 +653,7 @@ void
viewdb(const Arg *arg) {
Item *choice = getitem(0);
- if(!(choice && choice->ncols)) {
+ if(!choice) {
ui_set("status", "No database selected.");
return;
}
@@ -718,10 +718,9 @@ viewtable(const Arg *arg) {
void
viewtable_show(void) {
MYSQL_RES *res;
- char *tbl;
+ char tbl[MAXCOLSZ+1];
- tbl = ecalloc(1 + selview->choice->lens[0], sizeof(char));
- snprintf(tbl, 1 + selview->choice->lens[0], "%s", selview->choice->cols[0]);
+ snprintf(tbl, sizeof tbl, "%s", selview->choice->cols[0]);
if(!(res = mysql_exec("select * from `%s`", tbl)))
die("select from `%s`", tbl);
mysql_fillview(res, 1);