Skip to content

Commit

Permalink
Set initial capacity to 50 chars.
Browse files Browse the repository at this point in the history
	modified:   src/nms.c
  • Loading branch information
bartobri committed Sep 20, 2017
1 parent 39c02de commit 30bd00f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/nms.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
#include "nmseffect.h"

#define VERSION "0.3.3"
#define INITIAL_CAPACITY 50
#define INPUT_GROWTH_FACTOR 2

int main(int argc, char *argv[]) {
int c, o, inSize = 0, inCapacity = 0;
int c, o, inSize = 0, inCapacity = INITIAL_CAPACITY;
char *input = NULL;

// Processing command arguments
Expand Down Expand Up @@ -44,12 +45,17 @@ int main(int argc, char *argv[]) {
return 1;
}
}

if ((input = malloc(inCapacity + 1)) == NULL) {
fprintf (stderr, "Memory Allocation Error! Quitting...\n");
return 1;
}

// Geting input
while ((c = getchar()) != EOF) {
++inSize;
if (inSize > inCapacity) {
inCapacity = inCapacity == 0 ? INPUT_GROWTH_FACTOR : inCapacity * INPUT_GROWTH_FACTOR;
inCapacity *= INPUT_GROWTH_FACTOR;
input = realloc(input, inCapacity + 1);
}
input[inSize - 1] = c;
Expand Down

0 comments on commit 30bd00f

Please sign in to comment.