提交 e3042683 编写于 作者: J Jim Meyering

absolutePathFromBaseFile: avoid an unnecessary use of assert

* src/util/storage_file.c (absolutePathFromBaseFile): While this use
of virAsprintf is slightly cleaner than using stpncpy(stpcpy(...,
it does impose an artificial limitation on the length of the base_file
name.  Rather than asserting that it does not exceed INT_MAX, return
NULL when it does.
上级 69cf62ad
......@@ -26,7 +26,6 @@
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#include "dirname.h"
#include "ignore-value.h"
#include "memory.h"
......@@ -251,7 +250,8 @@ absolutePathFromBaseFile(const char *base_file, const char *path)
return strdup(path);
/* Ensure that the following cast-to-int is valid. */
assert (d_len <= INT_MAX);
if (d_len > INT_MAX)
return NULL;
ignore_value(virAsprintf(&res, "%.*s/%s", (int) d_len, base_file, path));
return res;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册