Replace a couple of local IO buffers with a vector

This commit is contained in:
Panu Matilainen 2024-04-23 16:49:18 +03:00
parent 99e26b9df5
commit bac494c35c
2 changed files with 7 additions and 7 deletions

View File

@ -5,6 +5,7 @@
#include "system.h"
#include <string>
#include <vector>
#include <stdarg.h>
#include <pthread.h>
@ -1925,7 +1926,7 @@ static int loadMacroFile(rpmMacroContext mc, const char * fn)
{
FILE *fd = fopen(fn, "r");
size_t blen = MACROBUFSIZ;
char *buf = (char *)xmalloc(blen);
std::vector<char> buf(blen);
int rc = -1;
int nfailed = 0;
int lineno = 0;
@ -1939,11 +1940,11 @@ static int loadMacroFile(rpmMacroContext mc, const char * fn)
RMIL_MACROFILES, ME_FUNC);
buf[0] = '\0';
while ((nlines = rdcl(buf, blen, fd)) > 0) {
while ((nlines = rdcl(buf.data(), blen, fd)) > 0) {
char c, *n;
lineno += nlines;
n = buf;
n = buf.data();
SKIPBLANK(n, c);
if (c != '%')
@ -1960,7 +1961,6 @@ static int loadMacroFile(rpmMacroContext mc, const char * fn)
rc = (nfailed > 0);
exit:
_free(buf);
return rc;
}

View File

@ -1,6 +1,7 @@
#include "system.h"
#include <filesystem>
#include <vector>
#include <sys/types.h>
#include <sys/stat.h>
@ -29,14 +30,14 @@ int rpmDoDigest(int algo, const char * fn,int asAscii, unsigned char * digest)
{
unsigned char * dig = NULL;
size_t diglen, buflen = 32 * BUFSIZ;
unsigned char *buf = (unsigned char *)xmalloc(buflen);
std::vector<uint8_t> buf(buflen);
int rc = 0;
FD_t fd = Fopen(fn, "r.ufdio");
if (fd) {
fdInitDigest(fd, algo, 0);
while ((rc = Fread(buf, sizeof(*buf), buflen, fd)) > 0) {};
while ((rc = Fread(buf.data(), 1, buflen, fd)) > 0) {};
fdFiniDigest(fd, algo, (void **)&dig, &diglen, asAscii);
}
@ -47,7 +48,6 @@ int rpmDoDigest(int algo, const char * fn,int asAscii, unsigned char * digest)
}
dig = _free(dig);
free(buf);
Fclose(fd);
return rc;