❦ 26 mars 2016 18:16 +0100, Vincent Bernat <[email protected]> : >> Hi, Vincent! Thanks for your answer! >> I made some tests today. Yes, it crashes only if hostname contains an >> odd number of symbols! > > So, it should be easy to fix. Baptiste, do you want a patch or are my > explanations enough?
I am trying to look if there are other cases of alignment problem. Some time ago, gcc was emitting a warning if this was the case (-Wcast-align) but there was too many false positives and this is not the case anymore. It would be easier to spot the cast problems if there was less of them. Willy, you always cast for functions returning void*. This is not needed. For example: l = (struct listener *)calloc(1, sizeof(struct listener)); Could be just: l = calloc(1, sizeof(struct listener)); C always do the casting from void* to the appropriate type used on LHS. I don't have reference, but this is C89, so even very old compilers will do the casting just fine. I can propose a (large) patch to remove all those casts (using a semantic patch to not miss anything). Here is a preview (for master, only src/): https://gist.github.com/dc61d8b035545dc24efd After this patch, this leaves 52 casts to be examined for alignment (git grep '= (struct.*\*)', not rocket science). Of course, no need to really apply the patch to examine those, but in the future, this may be easier without those casts. Patch is incomplete, I can also remove SSL_get_app_data casts, I see another problematic cast in src/shctx.c: cur = (struct shared_block *)((char *)prev + sizeof(struct shared_block)); But prev is already a "struct shared_block *". So it's OK. It would be easier to read as: cur = prev + 1; I am pretty sure that in src/connection.c, make_tlv() and other TLV handling stuff are problematic, unless there is some guarantee that TLV are memory-aligned but as I suppose this is a wire format, this can't be the case. I don't see any other problematic cases. To sum up: 1. can we remove uneeded void* cast? 2. correct dns.c 3. correct TLV handling in connection.c 4. simplify the occurrence in shctx.c (or not worth it) -- Avoid multiple exits from loops. - The Elements of Programming Style (Kernighan & Plauger)

