1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

cov: make read buffer obviously zero ended

Coverity doesn't get the idea from memset() here.
This commit is contained in:
Zdenek Kabelac 2021-09-20 01:57:06 +02:00
parent 6c87e98ee3
commit 752a9ec4b4
3 changed files with 4 additions and 4 deletions

View File

@ -522,7 +522,7 @@ int config_file_read_fd(struct dm_config_tree *cft, struct device *dev, dev_io_r
if (!(dev->flags & DEV_REGULAR) || size2) if (!(dev->flags & DEV_REGULAR) || size2)
use_plain_read = 0; use_plain_read = 0;
if (!(buf = malloc(size + size2))) { if (!(buf = zalloc(size + size2))) {
log_error("Failed to allocate circular buffer."); log_error("Failed to allocate circular buffer.");
return 0; return 0;
} }

View File

@ -2955,7 +2955,7 @@ static int _read_metadata_file(struct cmd_context *cmd, struct metadata_file *mf
goto out; goto out;
} }
if (!(text_buf = zalloc(text_size + 1))) if (!(text_buf = malloc(text_size + 1)))
goto_out; goto_out;
rv = read(fd, text_buf, text_size); rv = read(fd, text_buf, text_size);
@ -2964,8 +2964,7 @@ static int _read_metadata_file(struct cmd_context *cmd, struct metadata_file *mf
free(text_buf); free(text_buf);
goto out; goto out;
} }
text_buf[text_size++] = 0; /* null terminating byte */
text_size += 1; /* null terminating byte */
if (close(fd)) if (close(fd))
stack; stack;

View File

@ -223,6 +223,7 @@ static int _online_pvid_file_read(char *path, int *major, int *minor, char *vgna
log_warn("No info in %s", path); log_warn("No info in %s", path);
return 0; return 0;
} }
buf[rv] = 0; /* \0 terminated buffer */
if (sscanf(buf, "%d:%d", major, minor) != 2) { if (sscanf(buf, "%d:%d", major, minor) != 2) {
log_warn("No device numbers in %s", path); log_warn("No device numbers in %s", path);