[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tyndur-devel] [PATCH 1/2] shell: bincat: Kein fseek auf NULL aufrufen
! shell: Wenn bincat die Datei nicht öffnen kann, muss es sofort einen
Fehler zurückgeben und nicht erst noch den NULL-Pointer an fseek
weitergeben, damit es garantiert rot gibt.
Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
src/modules/c/shell/cmds/bincat.c | 51 +++++++++++++++++++------------------
1 files changed, 26 insertions(+), 25 deletions(-)
diff --git a/src/modules/c/shell/cmds/bincat.c b/src/modules/c/shell/cmds/bincat.c
index d21d4d9..41066a2 100644
--- a/src/modules/c/shell/cmds/bincat.c
+++ b/src/modules/c/shell/cmds/bincat.c
@@ -135,43 +135,44 @@ void bincat_display_usage(void);
}
FILE* file = fopen(path, "r");
+ if (file == NULL) {
+ printf(TMS(bincat_opening_error,
+ "Konnte '%s' nicht zum lesen öffnen!\n"), path);
+ return EXIT_FAILURE;
+ }
+
+ char buffer[BLOCK_SIZE];
+ size_t size;
fseek(file, start, SEEK_SET);
m = start - 8;
- if (file == NULL) {
- printf(TMS(bincat_opening_error,
- "Konnte '%s' nicht zum lesen öffnen!\n"), path);
- return -1;
- } else {
- char buffer[BLOCK_SIZE];
- size_t size;
- while (feof(file) != EOF && (total_read <= length || length == 0)) {
+ while (feof(file) != EOF && (total_read <= length || length == 0)) {
- size = fread(buffer, 1, BLOCK_SIZE, file);
+ size = fread(buffer, 1, BLOCK_SIZE, file);
- total_read += size;
+ total_read += size;
- if (length && (total_read > length)) {
- size -= total_read - length;
- }
+ if (length && (total_read > length)) {
+ size -= total_read - length;
+ }
- for (n=0; n < size; n++) {
- if ((n % 8) == 0) {
- if (n == 8) {
- printf("0x%08x", m);
- }
- m += 8;
- printf("\n");
- printf("0x%08x: ", m);
+ for (n=0; n < size; n++) {
+ if ((n % 8) == 0) {
+ if (n == 8) {
+ printf("0x%08x", m);
}
-
- printf("0x%02x ", ((uint32_t) buffer[n]) & 0xFF);
+ m += 8;
+ printf("\n");
+ printf("0x%08x: ", m);
}
- }
- fclose(file);
+ printf("0x%02x ", ((uint32_t) buffer[n]) & 0xFF);
+ }
}
+
+ fclose(file);
+
printf("\n");
return EXIT_SUCCESS;
}
--
1.6.0.2