libcoap icon indicating copy to clipboard operation
libcoap copied to clipboard

Recheck source code in coap_dtls_new_context()

Open elfring opened this issue 6 years ago • 8 comments

The implementation of the function “coap_dtls_new_context” does not contain a goto statement. The jump label “fail” can not be reached. How do you think about to adjust (or delete) a bit of source code here?

elfring avatar Jan 26 '19 13:01 elfring

Unfortunately, it does contain a goto failstatement. I would like to get rid of that side-effect of the macro G_CHECK, i.e., make the jump obvious.

obgm avatar Jan 26 '19 14:01 obgm

@obgm Wouldn't removing the goto fail statement from G_CHECK lead to lots of duplicate code as you'd have to put in if ... goto fail each time. Wouldn't it it be better to rename the macro to make it obvious what it does?

How about "G_RET_ZERO_OR_FAIL"?

oliness avatar Jan 30 '19 12:01 oliness

It is a macro, so this is duplicate source code anyway. But I agree that renaming would be better than nothing. @mrdeep1 do you have an opinion on this?

obgm avatar Jan 30 '19 12:01 obgm

The issue with a long macro name is that there is likelihood of exceeding the line length of 80 characters. [Anything longer than G_CHECK will require lines to be split in most cases in the current code]

Many of the GnuTLS examples make the use of just CHECK (which normally triggers and assert()), I decided to prefix with G_ to indicate this was a CHECK for GnuTLS.

That said, I am all for better readability of the code making it self documenting where possible. To that end, I would prefer something like G_CHECK_FAIL.

mrdeep1 avatar Jan 30 '19 12:01 mrdeep1

Sounds good.

obgm avatar Jan 30 '19 12:01 obgm

Ok is everyone fine with changing G_CHECK to G_CHECK_FAIL? If so I'll submit a pr, ensuring lines are split when needed.

oliness avatar Jan 30 '19 14:01 oliness

@oliness If you are happy to do the work, that is fine by me.

mrdeep1 avatar Jan 30 '19 14:01 mrdeep1

@oliness Are you going to be able to do this work?

mrdeep1 avatar Feb 20 '19 21:02 mrdeep1