commit 6bc931975d224e235882acb70a5564008f76cb82
parent 59b5dc6b98525f6420838e80fbf52776d1c26184
Author: pancake <pancake@nopcode.org>
Date: Mon, 30 Aug 2010 22:53:00 +0200
check popen return value in calc example
Diffstat:
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/t/calc.c b/t/calc.c
@@ -6,6 +6,8 @@ static int bufferi = 0;
static char buffer[256];
static void button(SwkEvent *e) {
+ FILE *pd;
+ static char buffer2[sizeof(buffer)+32];
if(e->type==EClick) {
int key = *e->box->text;
switch(key) {
@@ -17,15 +19,13 @@ static void button(SwkEvent *e) {
buffer[--bufferi] = 0;
break;
case '=':
- {
- FILE *pd;
- static char buffer2[sizeof(buffer)+32];
snprintf(buffer2, sizeof(buffer2), "echo '%s' | bc -q", buffer);
pd = popen(buffer2, "r");
- fgets(buffer, sizeof(buffer), pd);
- bufferi = strlen(buffer)-1;
- buffer[bufferi] = 0;
- pclose(pd);
+ if(pd) {
+ fgets(buffer, sizeof(buffer), pd);
+ bufferi = strlen(buffer)-1;
+ buffer[bufferi] = 0;
+ pclose(pd);
}
break;
default: