Browse Source

Explicitly print out-of-memory message to avoid tricking the user into

thinking that a command executed successfully.
tags/v0.9.3
Michael Brown 17 years ago
parent
commit
b613086bfe
1 changed files with 7 additions and 7 deletions
  1. 7
    7
      src/hci/readline.c

+ 7
- 7
src/hci/readline.c View File

@@ -85,7 +85,7 @@ char * readline ( const char *prompt ) {
85 85
 		.cursor = 0,
86 86
 	};
87 87
 	int key;
88
-	char *line = NULL;
88
+	char *line;
89 89
 
90 90
 	if ( prompt )
91 91
 		printf ( "%s", prompt );
@@ -97,17 +97,17 @@ char * readline ( const char *prompt ) {
97 97
 		switch ( key ) {
98 98
 		case 0x0d: /* Carriage return */
99 99
 		case 0x0a: /* Line feed */
100
+			putchar ( '\n' );
100 101
 			line = strdup ( buf );
101
-			goto out;
102
+			if ( ! line )
103
+				printf ( "Out of memory\n" );
104
+			return line;
102 105
 		case 0x03: /* Ctrl-C */
103
-			goto out;
106
+			putchar ( '\n' );
107
+			return NULL;
104 108
 		default:
105 109
 			/* Do nothing */
106 110
 			break;
107 111
 		}
108 112
 	}
109
-
110
- out:
111
-	putchar ( '\n' );
112
-	return line;
113 113
 }

Loading…
Cancel
Save