Simplify memory allocation in read_file 91/72991/2
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 3 Jun 2016 11:14:56 +0000 (13:14 +0200)
committerLukasz Pawelczyk <l.pawelczyk@samsung.com>
Mon, 6 Jun 2016 12:43:02 +0000 (14:43 +0200)
Change-Id: Ia3cc7dd2d04fb4279ec3cc60c5858f84ace20daa

examples/misc.c

index 5a121a8..693044d 100644 (file)
@@ -92,16 +92,9 @@ int read_file(const char *path, char **data, size_t *data_len)
                size_t read = fread(tmp, 1, BUF_SIZE, f);
 
                if (read > 0) {
-                       if (buf == NULL) {
-                               if (yaca_malloc(read, (void**)&buf) != YACA_ERROR_NONE) {
-                                       ret = -1;
-                                       break;
-                               }
-                       } else {
-                               if (yaca_realloc(buf_len + read, (void**)&buf) != YACA_ERROR_NONE) {
-                                       ret = -1;
-                                       break;
-                               }
+                       if (yaca_realloc(buf_len + read, (void**)&buf) != YACA_ERROR_NONE) {
+                               ret = -1;
+                               break;
                        }
 
                        memcpy(buf + buf_len, tmp, read);