Skip to content

Commit 2238724

Browse files
committed
Avoid doing complex operations in RB_OBJ_WRITE macro call
A C macro might execute the parameter twice, so that fit_to_result() would be called twice. Although this is just hypotetical, storing in a local variable ensures calling twice will not happen.
1 parent 38b4318 commit 2238724

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ext/pg_result.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,8 +1424,9 @@ pgresult_type_map_set(VALUE self, VALUE typemap)
14241424
/* Check type of method param */
14251425
TypedData_Get_Struct(typemap, t_typemap, &pg_typemap_type, p_typemap);
14261426

1427-
RB_OBJ_WRITE(self, &this->typemap, p_typemap->funcs.fit_to_result( typemap, self ));
1428-
this->p_typemap = RTYPEDDATA_DATA( this->typemap );
1427+
typemap = p_typemap->funcs.fit_to_result( typemap, self );
1428+
RB_OBJ_WRITE(self, &this->typemap, typemap);
1429+
this->p_typemap = RTYPEDDATA_DATA( typemap );
14291430

14301431
return typemap;
14311432
}

0 commit comments

Comments
 (0)