[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] libpoke/ios-dev-stream.c: free buffer only in read mode

From: Mohammad-Reza Nabipoor
Subject: Re: [PATCH] libpoke/ios-dev-stream.c: free buffer only in read mode
Date: Sat, 17 Oct 2020 17:09:32 +0330

Hi, Jose.

On Sat, Oct 17, 2020 at 12:23:12PM +0200, Jose E. Marchesi wrote:
> Wouldn't it be better to make sure to initialize sio->buffer to NULL
> when it is not used, and then to either:

Currently the `buffer` field is inside an anonymous union (and shares the
storage with `uint64_t write_offset`).
If we want to check the nullability, we should remove the `union`.

Like this:

struct ios_dev_stream
  char *handler;
  FILE *file;
  uint64_t flags;
  struct ios_buffer *buffer;
  uint64_t write_offset;

> 1. Document (in ios-buffer.h) that ios_buffer_free works as a nop if
>    NULL is passed, or
> 2. Check for sio->buffer == NULL in ios_dev_stream_close and call (or
>    not) ios_buffer_free accordingly.

I prefer the option 2 (plus adding an explicit pre-condition that `buffer` must
be non-null).

But I guess option 1 is more popular among C programmers.

Should I remove the `union`?
Which approach do you think is the best for `ios_buffer_free(NULL)`?
NOP or assertion?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]