@@ -3422,12 +3422,18 @@ int git_repository_hashfile(
34223422
34233423static int checkout_message (git_str * out , git_reference * old , const char * new )
34243424{
3425+ const char * idstr ;
3426+
34253427 git_str_puts (out , "checkout: moving from " );
34263428
3427- if (git_reference_type (old ) == GIT_REFERENCE_SYMBOLIC )
3429+ if (git_reference_type (old ) == GIT_REFERENCE_SYMBOLIC ) {
34283430 git_str_puts (out , git_reference__shorthand (git_reference_symbolic_target (old )));
3429- else
3430- git_str_puts (out , git_oid_tostr_s (git_reference_target (old )));
3431+ } else {
3432+ if ((idstr = git_oid_tostr_s (git_reference_target (old ))) == NULL )
3433+ return -1 ;
3434+
3435+ git_str_puts (out , idstr );
3436+ }
34313437
34323438 git_str_puts (out , " to " );
34333439
@@ -3463,8 +3469,11 @@ static int detach(git_repository *repo, const git_oid *id, const char *new)
34633469 if ((error = git_object_peel (& peeled , object , GIT_OBJECT_COMMIT )) < 0 )
34643470 goto cleanup ;
34653471
3466- if (new == NULL )
3467- new = git_oid_tostr_s (git_object_id (peeled ));
3472+ if (new == NULL &&
3473+ (new = git_oid_tostr_s (git_object_id (peeled ))) == NULL ) {
3474+ error = -1 ;
3475+ goto cleanup ;
3476+ }
34683477
34693478 if ((error = checkout_message (& log_message , current , new )) < 0 )
34703479 goto cleanup ;
@@ -3552,6 +3561,7 @@ int git_repository_detach_head(git_repository *repo)
35523561 git_reference * old_head = NULL , * new_head = NULL , * current = NULL ;
35533562 git_object * object = NULL ;
35543563 git_str log_message = GIT_STR_INIT ;
3564+ const char * idstr ;
35553565 int error ;
35563566
35573567 GIT_ASSERT_ARG (repo );
@@ -3565,7 +3575,12 @@ int git_repository_detach_head(git_repository *repo)
35653575 if ((error = git_object_lookup (& object , repo , git_reference_target (old_head ), GIT_OBJECT_COMMIT )) < 0 )
35663576 goto cleanup ;
35673577
3568- if ((error = checkout_message (& log_message , current , git_oid_tostr_s (git_object_id (object )))) < 0 )
3578+ if ((idstr = git_oid_tostr_s (git_object_id (object ))) == NULL ) {
3579+ error = -1 ;
3580+ goto cleanup ;
3581+ }
3582+
3583+ if ((error = checkout_message (& log_message , current , idstr )) < 0 )
35693584 goto cleanup ;
35703585
35713586 error = git_reference_create (& new_head , repo , GIT_HEAD_FILE , git_reference_target (old_head ),
0 commit comments