rnp icon indicating copy to clipboard operation
rnp copied to clipboard

Explicitly initialize POD struct fields.

Open ni4 opened this issue 4 years ago • 6 comments

Description

As from discussion at https://github.com/rnpgp/rnp/pull/1109#issuecomment-624612517 we should {} - initialize all struct fields to avoid possible further initialization errors.

ni4 avatar May 06 '20 17:05 ni4

maybe just memset(&s, 0, sizeof some_struct_t); ?

antonsviridenko avatar May 11 '20 16:05 antonsviridenko

maybe just memset(&s, 0, sizeof some_struct_t); ?

It's not very C++-y, it relies on all members remaining POD, and it seems maybe more likely to be a runtime vs compile-time thing.

dewyatt avatar May 11 '20 17:05 dewyatt

maybe just memset(&s, 0, sizeof some_struct_t); ?

That will not work within the migration to C++, when, for instance, list variables will become a std::vector or std::map.

ni4 avatar May 11 '20 19:05 ni4

So, I'm going to replace calloc with new and free with delete, right?

rrrooommmaaa avatar Sep 14 '20 18:09 rrrooommmaaa

for all these:

  • rnp_ffi_st
  • rnp_key_handle_st
  • rnp_uid_handle_st
  • rnp_signature_handle_st
  • rnp_recipient_handle_st
  • rnp_symenc_handle_st
  • rnp_input_st
  • rnp_output_st
  • rnp_op_generate_st
  • rnp_op_sign_st
  • rnp_op_sign_signature_st
  • rnp_op_verify_signature_st
  • rnp_op_verify_st
  • rnp_op_encrypt_st
  • rnp_identifier_iterator_st

rrrooommmaaa avatar Sep 14 '20 18:09 rrrooommmaaa

Please not yet, if possible - I have some postponed code which will definitely conflict with those changes (see https://github.com/ni4/rnp/pull/4)

ni4 avatar Sep 14 '20 18:09 ni4