13

Minor stuff ... Allocate to the object, not type The below is easier to maintain. // char **aux = malloc(sizeof(char *)) char **aux = malloc(sizeof *aux) // aux[0] = malloc(bufsize * sizeof(char)); aux[0] = malloc(sizeof *(aux[0]) * bufsize); Avoid Exploit Below code is undefined behavior is the first character of user input is the null character. It ...


10

So, you basically rewrote the strtok function in ANSI C. The difference is that you allocate memory for each substring while TOK modifies the original string by adding \0 characters in the place of delimiters. This means that you keep allocating more and more memory, while you can just make a copy of the whole string and use strtok to modify the copy you ...


5

Review points: removeFirst on an empty list should be a no-op, (or throw an exception). last was dangling. Setting things to null of the removed first node, is not done in OOP, is left to the garbage collection. This also removes the need for an extra variable. And the resulting binary code is smaller. So: public void removeFirst() { if (first != null)...


3

Your usage of realloc is wrong: aux = realloc(aux, len * sizeof(char *)); The trouble is that if realloc() fails (i.e. it can not find a bigger block) it does not release aux but returns NULL. So the correct usage is: char** tmp = realloc(aux, len * sizeof(char *)); if (tmp == NULL) { /* SOME ERROR HANDLING */ // free(aux); exit(0); // or ...


2

Major issue You allocate memory that can take a single pointer for aux, then start accessing off the end of it with aux[len-1]. These sort of issues create exploitable security vulnerabilities. For an array of pointers I would have expected to see use of calloc(). Try re-running using something like Clang's address sanitizer (for example, with cc split.c ...


Only top voted, non community-wiki answers of a minimum length are eligible