Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
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

All the code looks like you are very experienced since you didn't make any obvious mistakes. Some small things to consider: I'd compile the release binary with assertions enabled since I prefer an obvious crash over undefined behavior. Since you don't include <assert.h> at all, you don't need the -DNDEBUG flags at all since they won't make any ...


3

Welcome to Code Review! Bugs For every node you insert, next is null. Encapsulation Your code is written almost exclusively using C features. First things first, instead of using a single global variable, use a class to encapsulate the data structure. class Stack { public: Stack() = default; Stack(const Stack&) = delete; Stack& ...


3

I'll second what Gloweye said in this answer, namely that assert should not be used for control flow. Here is a solution which combines the other answers: def smallest_letter(str_in: str) -> str: min_ord = 128 for curr_char_ord in (ord(c) for c in str_in): if curr_char_ord > 127: raise ValueError(f'Character {chr(...


3

For the second point, since it's easier, typing has an Any: from typing import List, Any . . ., variables: List[Any], . . . For the first, you're just doing a reduction over variables: from typing import List, Any from functools import reduce def format_string(string: str, variables: List[Any]) -> str: return reduce(lambda s, val: s.replace("[*]", ...


3

Regarding min(string): Python exceeding your expectations. It happens a lot. assert All assert statements can be disabled with a switch to the interpreter, and sometimes are. Therefore, they're not suitable for flow control. I think you should replace: for character in string: assert ord(character) <= 127 With: for character in string: if ord(...


3

I may or may not have seen a certain movie in the cinema, but the Batman in me wants to say this: Not to mention that semicolons don't hurt either. Also, per @Blindman67, it seems that you are pushing complexity down to the callers. It seems to me a number of callbacks would only want to run for a given key, forcing callers to check the key value is not ...


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 ...


2

The code looks nice! Here are my suggestions. Testing Your code passes your test, but there are quite a few bugs that can be easily caught by testing! Make sure that every functionality is tested so you don't miss some bugs. The compiler flags Right now, you are using this command to compile the code: g++ -std=c++17 -g -Wall main.cpp -o main There ...


2

Of course min("3sdsdf44ldfkTsdfnsnприветsdfa5É") (contains unicode chars) approach won't be suitable in case if validating/requiring only ASCII chars. Issues of initial approach : validating empty string. To ensure non-empty input string we'll add a simple assertion at start: assert string != "", "Empty string" doubled traversals. On valid input strings ...


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