@@ -817,8 +817,7 @@ CAMLprim value PQgetvalue_stub(value v_res, intnat tup_num, intnat field_num)
817
817
else {
818
818
/* Assume binary format! */
819
819
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 ;
822
821
}
823
822
CAMLreturn (v_str );
824
823
}
@@ -872,8 +871,7 @@ static value unescape_bytea(const char *str)
872
871
char * buf = (char * ) PQunescapeBytea ((unsigned char * ) str , & res_len );
873
872
if (buf == NULL ) caml_failwith ("Postgresql: illegal bytea string" );
874
873
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 );
877
875
PQfreemem (buf );
878
876
return v_res ;
879
877
}
@@ -924,8 +922,7 @@ CAMLprim value PQgetescval_stub(value v_res, intnat tup_num, intnat field_num)
924
922
} else {
925
923
/* Assume binary format! */
926
924
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 ;
929
926
}
930
927
CAMLreturn (v_str );
931
928
}
@@ -1138,8 +1135,7 @@ CAMLprim value PQescapeStringConn_stub(
1138
1135
caml_stat_free (buf );
1139
1136
caml_failwith ("Postgresql.escape_string_conn: failed to escape string" );
1140
1137
} 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 );
1143
1139
caml_stat_free (buf );
1144
1140
return v_res ;
1145
1141
}
@@ -1161,8 +1157,7 @@ CAMLprim value PQescapeByteaConn_stub(
1161
1157
(char * ) PQescapeByteaConn (
1162
1158
get_conn (v_conn ),
1163
1159
(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 );
1166
1161
PQfreemem (buf );
1167
1162
return v_res ;
1168
1163
}
@@ -1287,8 +1282,7 @@ CAMLprim value PQgetCopyData_stub(value v_conn, intnat async)
1287
1282
case -2 :
1288
1283
CAMLreturn (Val_int (2 )); /* Get_copy_error */
1289
1284
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 );
1292
1286
PQfreemem (buf );
1293
1287
v_res = caml_alloc_small (1 , 0 ); /* Get_copy_data */
1294
1288
Field (v_res , 0 ) = v_buf ;
0 commit comments