On 27.06.19 17:26, Denis Plotnikov wrote: > > > On 19.06.2019 13:09, Vladimir Sementsov-Ogievskiy wrote: >> 10.06.2019 16:21, Denis Plotnikov wrote: >>> The patch allows to provide a pattern file for write >>> command. There was no similar ability before. >>> >>> Signed-off-by: Denis Plotnikov <dplotni...@virtuozzo.com> >>> --- >>> v6: >>> * the pattern file is read once to reduce io >>> >>> v5: >>> * file name initiated with null to make compilers happy >>> >>> v4: >>> * missing signed-off clause added >>> >>> v3: >>> * missing file closing added >>> * exclusive flags processing changed >>> * buffer void* converted to char* to fix pointer arithmetics >>> * file reading error processing added >>> --- >>> qemu-io-cmds.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++---- >>> 1 file changed, 82 insertions(+), 6 deletions(-)
[...] >>> + if (l < len) { >>> + char *file_buf = g_malloc(sizeof(char) * l); Note that sizeof(char) is guaranteed to be 1. (C1x standard, 6.5.3.4, paragraph 4.) >>> + memcpy(file_buf, buf, l); >> >> I see no reason to copy it, you can just use buf_origin pointer >> instead. > I use buf_origin to save the beginning pointer to return it from the > function avoiding later calculation of the beginning address since > pointer of the buf is changed in the loop. The point is that you don’t need file_buf. You can drop it, replace all occurrences of file_buf by buf_origin, and probably use memmove instead of memcpy. Max
signature.asc
Description: OpenPGP digital signature