Skip to content

Commit

Permalink
avoids DATAPTR
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Jun 23, 2024
1 parent d4e4b3e commit 5339df7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ static SEXP rawToChar(const unsigned char *buf, const size_t sz) {
if (sz - i > 1) {
REprintf("data could not be converted to a character string\n");
out = Rf_allocVector(RAWSXP, sz);
memcpy(DATAPTR(out), buf, sz);
memcpy(SB_DATAPTR(out), buf, sz);
return out;
}

Expand Down Expand Up @@ -377,7 +377,7 @@ SEXP secretbase_base64enc(SEXP x, SEXP convert) {
out = rawToChar(buf, olen);
} else {
out = Rf_allocVector(RAWSXP, olen);
memcpy(DATAPTR(out), buf, olen);
memcpy(SB_DATAPTR(out), buf, olen);
}

R_Free(buf);
Expand Down Expand Up @@ -416,7 +416,7 @@ SEXP secretbase_base64dec(SEXP x, SEXP convert) {
switch (*(int *) DATAPTR_RO(convert)) {
case 0:
out = Rf_allocVector(RAWSXP, olen);
memcpy(DATAPTR(out), buf, olen);
memcpy(SB_DATAPTR(out), buf, olen);
break;
case 1:
out = rawToChar(buf, olen);
Expand Down
8 changes: 4 additions & 4 deletions src/secret.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static void mbedtls_sha3_finish(mbedtls_sha3_context *ctx, uint8_t *output, size

// secretbase - internals ------------------------------------------------------

static inline int R_Integer(SEXP x) {
static inline int nano_integer(SEXP x) {
int out;
switch (TYPEOF(x)) {
case INTSXP:
Expand Down Expand Up @@ -315,7 +315,7 @@ SEXP hash_to_sexp(unsigned char *buf, size_t sz, int conv) {
SEXP out;
if (conv == 0) {
out = Rf_allocVector(RAWSXP, sz);
memcpy(DATAPTR(out), buf, sz);
memcpy(SB_DATAPTR(out), buf, sz);
} else if (conv == 1) {
char cbuf[sz + sz + 1];
char *cptr = cbuf;
Expand All @@ -326,7 +326,7 @@ SEXP hash_to_sexp(unsigned char *buf, size_t sz, int conv) {
UNPROTECT(1);
} else {
out = Rf_allocVector(INTSXP, sz / sizeof(int));
memcpy(DATAPTR(out), buf, sz);
memcpy(SB_DATAPTR(out), buf, sz);
}

return out;
Expand All @@ -338,7 +338,7 @@ static SEXP secretbase_sha3_impl(const SEXP x, const SEXP bits, const SEXP conve
const int offset) {

const int conv = LOGICAL(convert)[0];
const int bt = R_Integer(bits);
const int bt = nano_integer(bits);
mbedtls_sha3_id id;

if (offset < 0) {
Expand Down
2 changes: 2 additions & 0 deletions src/secret.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <Rinternals.h>
#include <R_ext/Visibility.h>

#define SB_DATAPTR(x) (void *) DATAPTR_RO(x)

#define SB_R_SERIAL_VER 3
#define SB_SERIAL_HEADERS 6
#define SB_BUF_SIZE 4096
Expand Down

0 comments on commit 5339df7

Please sign in to comment.