@@ -20,14 +20,14 @@ SEXP mk_error(const int xc) {
2020SEXP nano_encode (SEXP object ) {
2121
2222 R_xlen_t xlen = Rf_xlength (object );
23+ unsigned char * buf ;
2324 size_t sz ;
2425 SEXP out ;
2526
2627 if (!Rf_isVectorAtomic (object ))
2728 error_return ("'data' is not an atomic vector type" );
2829 if (TYPEOF (object ) == STRSXP ) {
2930 const char * s ;
30- unsigned char * buf ;
3131 size_t np , outlen = 0 ;
3232 R_xlen_t i ;
3333 for (i = 0 ; i < xlen ; i ++ )
@@ -43,24 +43,28 @@ SEXP nano_encode(SEXP object) {
4343 } else {
4444 switch (TYPEOF (object )) {
4545 case REALSXP :
46+ buf = (unsigned char * ) REAL (object );
4647 sz = xlen * sizeof (double );
4748 out = Rf_allocVector (RAWSXP , sz );
48- memcpy (RAW (out ), REAL ( object ) , sz );
49+ memcpy (RAW (out ), buf , sz );
4950 break ;
5051 case INTSXP :
52+ buf = (unsigned char * ) INTEGER (object );
5153 sz = xlen * sizeof (int );
5254 out = Rf_allocVector (RAWSXP , sz );
53- memcpy (RAW (out ), INTEGER ( object ) , sz );
55+ memcpy (RAW (out ), buf , sz );
5456 break ;
5557 case LGLSXP :
58+ buf = (unsigned char * ) LOGICAL (object );
5659 sz = xlen * sizeof (int );
5760 out = Rf_allocVector (RAWSXP , sz );
58- memcpy (RAW (out ), LOGICAL ( object ) , sz );
61+ memcpy (RAW (out ), buf , sz );
5962 break ;
6063 case CPLXSXP :
64+ buf = (unsigned char * ) COMPLEX (object );
6165 sz = xlen * (sizeof (double ) + sizeof (double ));
6266 out = Rf_allocVector (RAWSXP , sz );
63- memcpy (RAW (out ), COMPLEX ( object ) , sz );
67+ memcpy (RAW (out ), buf , sz );
6468 break ;
6569 case RAWSXP :
6670 out = object ;
@@ -78,7 +82,7 @@ SEXP rawOneString(unsigned char *bytes, R_xlen_t nbytes, R_xlen_t *np) {
7882
7983 unsigned char * p ;
8084 R_xlen_t i ;
81- char * buf ;
85+ char * cbuf ;
8286 SEXP res ;
8387
8488 for (i = * np , p = bytes + (* np ); i < nbytes ; p ++ , i ++ )
@@ -89,11 +93,11 @@ SEXP rawOneString(unsigned char *bytes, R_xlen_t nbytes, R_xlen_t *np) {
8993 * np = i + 1 ;
9094 res = Rf_mkChar ((char * ) p );
9195 } else {
92- buf = R_chk_calloc (nbytes - (* np ) + 1 , 1 );
93- memcpy (buf , bytes + (* np ), nbytes - (* np ));
96+ cbuf = R_chk_calloc (nbytes - (* np ) + 1 , 1 );
97+ memcpy (cbuf , bytes + (* np ), nbytes - (* np ));
9498 * np = nbytes ;
95- res = Rf_mkChar (buf );
96- R_Free (buf );
99+ res = Rf_mkChar (cbuf );
100+ R_Free (cbuf );
97101 }
98102
99103 return res ;
@@ -646,7 +650,9 @@ SEXP rnng_recv(SEXP socket, SEXP mode, SEXP block, SEXP keep) {
646650 return mk_error (xc );
647651 }
648652 nng_msg * msgp = nng_aio_get_msg (aiop );
649- res = nano_decode (nng_msg_body (msgp ), nng_msg_len (msgp ), mod , kpr );
653+ buf = (unsigned char * ) nng_msg_body (msgp );
654+ sz = nng_msg_len (msgp );
655+ res = nano_decode (buf , sz , mod , kpr );
650656 nng_msg_free (msgp );
651657 nng_aio_free (aiop );
652658 }
@@ -701,6 +707,8 @@ SEXP rnng_ctx_recv(SEXP context, SEXP mode, SEXP timeout, SEXP keep) {
701707 const nng_duration dur = (nng_duration ) Rf_asInteger (timeout );
702708 const int mod = * INTEGER (mode ), kpr = * LOGICAL (keep );
703709 int xc ;
710+ unsigned char * buf ;
711+ size_t sz ;
704712 SEXP res ;
705713
706714 xc = nng_aio_alloc (& aiop , NULL , NULL );
@@ -717,7 +725,9 @@ SEXP rnng_ctx_recv(SEXP context, SEXP mode, SEXP timeout, SEXP keep) {
717725 }
718726
719727 nng_msg * msgp = nng_aio_get_msg (aiop );
720- res = nano_decode (nng_msg_body (msgp ), nng_msg_len (msgp ), mod , kpr );
728+ buf = (unsigned char * ) nng_msg_body (msgp );
729+ sz = nng_msg_len (msgp );
730+ res = nano_decode (buf , sz , mod , kpr );
721731 nng_msg_free (msgp );
722732 nng_aio_free (aiop );
723733
@@ -783,7 +793,7 @@ SEXP rnng_stream_recv(SEXP stream, SEXP mode, SEXP timeout, SEXP keep, SEXP byte
783793 SEXP res ;
784794
785795 iov .iov_len = xlen ;
786- iov .iov_buf = R_Calloc (xlen , unsigned char );
796+ iov .iov_buf = ( unsigned char * ) R_Calloc (xlen , unsigned char );
787797
788798 xc = nng_aio_alloc (& aiop , NULL , NULL );
789799 if (xc ) {
0 commit comments