Skip to main content
Code Review

Return to Revisions

1 of 3
Art
  • 186
  • 3

Standards

Note also that this project is developed to be compliant with the C11 standard.

Cool, let's find non-standard behavior.

The first thing that jumps out to me is your usage of double underscores.

Both C99 and C11 say (in section 7.1.3):

All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.

You include <malloc/malloc.h> everywhere. The only operating system where I could find that header file is MacOS. This is definitely not standard.

You seem to be very dependent on the function malloc_size in many places. As far as I know, only MacOS implements it.

Problematic behavior

In cstring_cmp and cstringbuffer_cmp you compare with the shortest string. Why not just use memcmp? Especially since what you're comparing aren't normal strings because they are not 0円-terminated.

It's possible to write 0円 into a cstringbuffer with cstringbuffer_write_char (and other functions) that will update the length to include that and later append further characters at the end of the buffers, but you're then using normal strcmp, strncpy, etc. to compare and copy the strings which will not do what you want. Either disallow 0円 explicitly or use functions that don't get confused by it.

Matters of taste

You're always allocating a struct on the stack, then malloc the same struct, then return a copy. Why? It seems like extra work.

Macros with magic goto error; with the error: label being outside of the macro are horrifying.

You do do { ... } while (0) in macros, this is good style. But you then defeat half the purpose of building macros this way by adding the ; inside the macro. for example if (foo) log_error("foo"); else do_something(); will not compile.

Art
  • 186
  • 3
default

AltStyle によって変換されたページ (->オリジナル) /