mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-11-14 00:14:07 +00:00
Replace non-standard VLAs with std::array (#2544)
This commit is contained in:
parent
c0219b38d1
commit
3ba8c2a139
@ -205,10 +205,9 @@ bool s3fs_md5_fd(int fd, off_t start, off_t size, md5_t* result)
|
||||
md5_init(&ctx_md5);
|
||||
|
||||
for(off_t total = 0; total < size; total += bytes){
|
||||
off_t len = 512;
|
||||
unsigned char buf[len];
|
||||
bytes = len < (size - total) ? len : (size - total);
|
||||
bytes = pread(fd, buf, bytes, start + total);
|
||||
std::array<char, 512> buf;
|
||||
bytes = buf.size() < (size - total) ? buf.size() : (size - total);
|
||||
bytes = pread(fd, buf.data(), bytes, start + total);
|
||||
if(0 == bytes){
|
||||
// end of file
|
||||
break;
|
||||
@ -260,10 +259,9 @@ bool s3fs_md5_fd(int fd, off_t start, off_t size, md5_t* result)
|
||||
}
|
||||
|
||||
for(off_t total = 0; total < size; total += bytes){
|
||||
off_t len = 512;
|
||||
char buf[len];
|
||||
bytes = len < (size - total) ? len : (size - total);
|
||||
bytes = pread(fd, buf, bytes, start + total);
|
||||
std::array<char, 512> buf;
|
||||
bytes = buf.size() < (size - total) ? buf.size() : (size - total);
|
||||
bytes = pread(fd, buf.data(), bytes, start + total);
|
||||
if(0 == bytes){
|
||||
// end of file
|
||||
break;
|
||||
@ -273,7 +271,7 @@ bool s3fs_md5_fd(int fd, off_t start, off_t size, md5_t* result)
|
||||
gcry_md_close(ctx_md5);
|
||||
return false;
|
||||
}
|
||||
gcry_md_write(ctx_md5, buf, bytes);
|
||||
gcry_md_write(ctx_md5, buf.data(), bytes);
|
||||
}
|
||||
memcpy(result->data(), gcry_md_read(ctx_md5, 0), result->size());
|
||||
gcry_md_close(ctx_md5);
|
||||
@ -305,10 +303,9 @@ bool s3fs_sha256_fd(int fd, off_t start, off_t size, sha256_t* result)
|
||||
sha256_init(&ctx_sha256);
|
||||
|
||||
for(off_t total = 0; total < size; total += bytes){
|
||||
off_t len = 512;
|
||||
unsigned char buf[len];
|
||||
bytes = len < (size - total) ? len : (size - total);
|
||||
bytes = pread(fd, buf, bytes, start + total);
|
||||
std::array<char, 512> buf;
|
||||
bytes = buf.size() < (size - total) ? buf.size() : (size - total);
|
||||
bytes = pread(fd, buf.data(), bytes, start + total);
|
||||
if(0 == bytes){
|
||||
// end of file
|
||||
break;
|
||||
@ -361,10 +358,9 @@ bool s3fs_sha256_fd(int fd, off_t start, off_t size, sha256_t* result)
|
||||
}
|
||||
|
||||
for(off_t total = 0; total < size; total += bytes){
|
||||
off_t len = 512;
|
||||
char buf[len];
|
||||
bytes = len < (size - total) ? len : (size - total);
|
||||
bytes = pread(fd, buf, bytes, start + total);
|
||||
std::array<char, 512> buf;
|
||||
bytes = buf.size() < (size - total) ? buf.size() : (size - total);
|
||||
bytes = pread(fd, buf.data(), bytes, start + total);
|
||||
if(0 == bytes){
|
||||
// end of file
|
||||
break;
|
||||
@ -374,7 +370,7 @@ bool s3fs_sha256_fd(int fd, off_t start, off_t size, sha256_t* result)
|
||||
gcry_md_close(ctx_sha256);
|
||||
return false;
|
||||
}
|
||||
gcry_md_write(ctx_sha256, buf, bytes);
|
||||
gcry_md_write(ctx_sha256, buf.data(), bytes);
|
||||
}
|
||||
memcpy(result->data(), gcry_md_read(ctx_sha256, 0), result->size());
|
||||
gcry_md_close(ctx_sha256);
|
||||
|
@ -175,10 +175,9 @@ bool s3fs_md5_fd(int fd, off_t start, off_t size, md5_t* result)
|
||||
md5ctx = PK11_CreateDigestContext(SEC_OID_MD5);
|
||||
|
||||
for(off_t total = 0; total < size; total += bytes){
|
||||
off_t len = 512;
|
||||
unsigned char buf[len];
|
||||
bytes = len < (size - total) ? len : (size - total);
|
||||
bytes = pread(fd, buf, bytes, start + total);
|
||||
std::array<unsigned char, 512> buf;
|
||||
bytes = buf.size() < (size - total) ? buf.size() : (size - total);
|
||||
bytes = pread(fd, buf.data(), bytes, start + total);
|
||||
if(0 == bytes){
|
||||
// end of file
|
||||
break;
|
||||
@ -188,7 +187,7 @@ bool s3fs_md5_fd(int fd, off_t start, off_t size, md5_t* result)
|
||||
PK11_DestroyContext(md5ctx, PR_TRUE);
|
||||
return false;
|
||||
}
|
||||
PK11_DigestOp(md5ctx, buf, bytes);
|
||||
PK11_DigestOp(md5ctx, buf.data(), bytes);
|
||||
}
|
||||
PK11_DigestFinal(md5ctx, result->data(), &md5outlen, result->size());
|
||||
PK11_DestroyContext(md5ctx, PR_TRUE);
|
||||
@ -229,10 +228,9 @@ bool s3fs_sha256_fd(int fd, off_t start, off_t size, sha256_t* result)
|
||||
sha256ctx = PK11_CreateDigestContext(SEC_OID_SHA256);
|
||||
|
||||
for(off_t total = 0; total < size; total += bytes){
|
||||
off_t len = 512;
|
||||
unsigned char buf[len];
|
||||
bytes = len < (size - total) ? len : (size - total);
|
||||
bytes = pread(fd, buf, bytes, start + total);
|
||||
std::array<unsigned char, 512> buf;
|
||||
bytes = buf.size() < (size - total) ? buf.size() : (size - total);
|
||||
bytes = pread(fd, buf.data(), bytes, start + total);
|
||||
if(0 == bytes){
|
||||
// end of file
|
||||
break;
|
||||
@ -242,7 +240,7 @@ bool s3fs_sha256_fd(int fd, off_t start, off_t size, sha256_t* result)
|
||||
PK11_DestroyContext(sha256ctx, PR_TRUE);
|
||||
return false;
|
||||
}
|
||||
PK11_DigestOp(sha256ctx, buf, bytes);
|
||||
PK11_DigestOp(sha256ctx, buf.data(), bytes);
|
||||
}
|
||||
PK11_DigestFinal(sha256ctx, result->data(), &sha256outlen, result->size());
|
||||
PK11_DestroyContext(sha256ctx, PR_TRUE);
|
||||
|
@ -241,10 +241,9 @@ bool s3fs_md5_fd(int fd, off_t start, off_t size, md5_t* result)
|
||||
EVP_DigestInit_ex(mdctx, EVP_md5(), nullptr);
|
||||
|
||||
for(off_t total = 0; total < size; total += bytes){
|
||||
const off_t len = 512;
|
||||
char buf[len];
|
||||
bytes = len < (size - total) ? len : (size - total);
|
||||
bytes = pread(fd, buf, bytes, start + total);
|
||||
std::array<char, 512> buf;
|
||||
bytes = buf.size() < (size - total) ? buf.size() : (size - total);
|
||||
bytes = pread(fd, buf.data(), bytes, start + total);
|
||||
if(0 == bytes){
|
||||
// end of file
|
||||
break;
|
||||
@ -255,7 +254,7 @@ bool s3fs_md5_fd(int fd, off_t start, off_t size, md5_t* result)
|
||||
return false;
|
||||
}
|
||||
// instead of MD5_Update
|
||||
EVP_DigestUpdate(mdctx, buf, bytes);
|
||||
EVP_DigestUpdate(mdctx, buf.data(), bytes);
|
||||
}
|
||||
|
||||
// instead of MD5_Final
|
||||
@ -301,10 +300,9 @@ bool s3fs_md5_fd(int fd, off_t start, off_t size, md5_t* result)
|
||||
MD5_Init(&md5ctx);
|
||||
|
||||
for(off_t total = 0; total < size; total += bytes){
|
||||
const off_t len = 512;
|
||||
char buf[len];
|
||||
bytes = len < (size - total) ? len : (size - total);
|
||||
bytes = pread(fd, buf, bytes, start + total);
|
||||
std::array<char, 512> buf;
|
||||
bytes = buf.size() < (size - total) ? buf.size() : (size - total);
|
||||
bytes = pread(fd, buf.data(), bytes, start + total);
|
||||
if(0 == bytes){
|
||||
// end of file
|
||||
break;
|
||||
@ -313,7 +311,7 @@ bool s3fs_md5_fd(int fd, off_t start, off_t size, md5_t* result)
|
||||
S3FS_PRN_ERR("file read error(%d)", errno);
|
||||
return false;
|
||||
}
|
||||
MD5_Update(&md5ctx, buf, bytes);
|
||||
MD5_Update(&md5ctx, buf.data(), bytes);
|
||||
}
|
||||
|
||||
MD5_Final(result->data(), &md5ctx);
|
||||
@ -360,10 +358,9 @@ bool s3fs_sha256_fd(int fd, off_t start, off_t size, sha256_t* result)
|
||||
EVP_DigestInit_ex(sha256ctx, md, nullptr);
|
||||
|
||||
for(off_t total = 0; total < size; total += bytes){
|
||||
const off_t len = 512;
|
||||
char buf[len];
|
||||
bytes = len < (size - total) ? len : (size - total);
|
||||
bytes = pread(fd, buf, bytes, start + total);
|
||||
std::array<char, 512> buf;
|
||||
bytes = buf.size() < (size - total) ? buf.size() : (size - total);
|
||||
bytes = pread(fd, buf.data(), bytes, start + total);
|
||||
if(0 == bytes){
|
||||
// end of file
|
||||
break;
|
||||
@ -373,7 +370,7 @@ bool s3fs_sha256_fd(int fd, off_t start, off_t size, sha256_t* result)
|
||||
EVP_MD_CTX_destroy(sha256ctx);
|
||||
return false;
|
||||
}
|
||||
EVP_DigestUpdate(sha256ctx, buf, bytes);
|
||||
EVP_DigestUpdate(sha256ctx, buf.data(), bytes);
|
||||
}
|
||||
EVP_DigestFinal_ex(sha256ctx, result->data(), nullptr);
|
||||
EVP_MD_CTX_destroy(sha256ctx);
|
||||
|
Loading…
Reference in New Issue
Block a user