@@ -817,8 +817,7 @@ CAMLprim value PQgetvalue_stub(value v_res, intnat tup_num, intnat field_num)
817817 else {
818818 /* Assume binary format! */
819819 size_t len = PQgetlength (res , tup_num , field_num );
820- v_str = len ? caml_alloc_string (len ) : v_empty_string ;
821- memcpy (String_val (v_str ), str , len );
820+ v_str = len ? caml_alloc_initialized_string (len , str ) : v_empty_string ;
822821 }
823822 CAMLreturn (v_str );
824823}
@@ -872,8 +871,7 @@ static value unescape_bytea(const char *str)
872871 char * buf = (char * ) PQunescapeBytea ((unsigned char * ) str , & res_len );
873872 if (buf == NULL ) caml_failwith ("Postgresql: illegal bytea string" );
874873 else {
875- value v_res = caml_alloc_string (res_len );
876- memcpy (String_val (v_res ), buf , res_len );
874+ value v_res = caml_alloc_initialized_string (res_len , buf );
877875 PQfreemem (buf );
878876 return v_res ;
879877 }
@@ -924,8 +922,7 @@ CAMLprim value PQgetescval_stub(value v_res, intnat tup_num, intnat field_num)
924922 } else {
925923 /* Assume binary format! */
926924 size_t len = PQgetlength (res , tup_num , field_num );
927- v_str = len ? caml_alloc_string (len ) : v_empty_string ;
928- memcpy (String_val (v_str ), str , len );
925+ v_str = len ? caml_alloc_initialized_string (len , str ) : v_empty_string ;
929926 }
930927 CAMLreturn (v_str );
931928}
@@ -1138,8 +1135,7 @@ CAMLprim value PQescapeStringConn_stub(
11381135 caml_stat_free (buf );
11391136 caml_failwith ("Postgresql.escape_string_conn: failed to escape string" );
11401137 } else {
1141- value v_res = caml_alloc_string (n_written );
1142- memcpy (String_val (v_res ), buf , n_written );
1138+ value v_res = caml_alloc_initialized_string (n_written , buf );
11431139 caml_stat_free (buf );
11441140 return v_res ;
11451141 }
@@ -1161,8 +1157,7 @@ CAMLprim value PQescapeByteaConn_stub(
11611157 (char * ) PQescapeByteaConn (
11621158 get_conn (v_conn ),
11631159 (unsigned char * ) String_val (v_from ) + pos_from , len , & res_len );
1164- value v_res = caml_alloc_string (-- res_len );
1165- memcpy (String_val (v_res ), buf , res_len );
1160+ value v_res = caml_alloc_initialized_string (-- res_len , buf );
11661161 PQfreemem (buf );
11671162 return v_res ;
11681163}
@@ -1287,8 +1282,7 @@ CAMLprim value PQgetCopyData_stub(value v_conn, intnat async)
12871282 case -2 :
12881283 CAMLreturn (Val_int (2 )); /* Get_copy_error */
12891284 default :
1290- v_buf = caml_alloc_string (res );
1291- memcpy (String_val (v_buf ), buf , res );
1285+ v_buf = caml_alloc_initialized_string (res , buf );
12921286 PQfreemem (buf );
12931287 v_res = caml_alloc_small (1 , 0 ); /* Get_copy_data */
12941288 Field (v_res , 0 ) = v_buf ;
0 commit comments