dm: hw: Replace sprintf with snprintf

Replace function sprintf with snprintf in device model

Tracked-On: #2079
Signed-off-by: Long Liu <long.liu@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Reviewed-by: <yonghua.huang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
Long Liu
2018-12-12 07:19:17 +00:00
committed by wenlingz
parent 69dc939243
commit eab7cd47ae
2 changed files with 10 additions and 4 deletions

View File

@@ -2307,7 +2307,7 @@ pci_ahci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts, int atapi)
char bident[16];
struct blockif_ctxt *bctxt;
struct pci_ahci_vdev *ahci_dev;
int ret, slots;
int ret, slots, rc;
uint8_t p;
MD5_CTX mdctx;
u_char digest[16];
@@ -2378,9 +2378,12 @@ pci_ahci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts, int atapi)
MD5_Init(&mdctx);
MD5_Update(&mdctx, opts, strlen(opts));
MD5_Final(digest, &mdctx);
sprintf(ahci_dev->port[p].ident,
rc = snprintf(ahci_dev->port[p].ident,
sizeof(ahci_dev->port[p].ident),
"ACRN--%02X%02X-%02X%02X-%02X%02X", digest[0],
digest[1], digest[2], digest[3], digest[4], digest[5]);
if (rc > sizeof(ahci_dev->port[p].ident))
WPRINTF("%s: digest is longer than ident\n", __func__);
/*
* Allocate blockif request structures and add them