{"thread":{"id":"41170","subject":"[PATCH] gitweb: Remove \"uninitialized value\" Perl warning","startedAt":"2016-01-12T03:31:56Z","lastAt":"2016-01-12T21:20:12Z","messageCount":2,"participants":["Øyvind A. Holm","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"275754","messageId":"1452569516-25657-1-git-send-email-sunny@sunbase.org","threadId":"41170","inReplyTo":null,"subject":"[PATCH] gitweb: Remove \"uninitialized value\" Perl warning","fromName":"Øyvind A. Holm","fromEmail":"sunny@sunbase.org","sentAt":"2016-01-12T03:31:56Z","receivedAt":"2016-01-12T03:31:56Z","isPatch":true,"sender":{"key":"sunny@sunbase.org","avatar":"https://avatars.githubusercontent.com/u/113445?v=4"},"body":"git_object(): Check if $type is defined before chomping it. This removes\na Perl warning in the server error log:\n\n  gitweb.cgi: Use of uninitialized value $type in scalar chomp at\n  [...]/gitweb.cgi line 7579., referer: [...]\n\nwhen trying to access a non-existing commit, for example:\n\n  http://HOST/?p=PROJECT.git;a=commit;h=NON_EXISTING_COMMIT\n\nSigned-off-by: Øyvind A. Holm <sunny@sunbase.org>\n---\n gitweb/gitweb.perl | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\nindex 7a5b23a..05d7910 100755\n--- a/gitweb/gitweb.perl\n+++ b/gitweb/gitweb.perl\n@@ -7576,7 +7576,7 @@ sub git_object {\n \t\t\tgit_cmd(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'\n \t\t\tor die_error(404, \"Object does not exist\");\n \t\t$type = <$fd>;\n-\t\tchomp $type;\n+\t\tdefined $type && chomp $type;\n \t\tclose $fd\n \t\t\tor die_error(404, \"Object does not exist\");\n \n-- \n2.7.0\n"},{"id":"275834","messageId":"CAPc5daVYHKehuDV7hFB9npw9qYt24jLTrnQr1LxDPdHQjWpkYQ@mail.gmail.com","threadId":"41170","inReplyTo":"xmqq4meitsce.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] gitweb: Remove \"uninitialized value\" Perl warning","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-01-12T21:20:12Z","receivedAt":"2016-01-12T21:20:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"On Tue, Jan 12, 2016 at 1:12 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Øyvind A. Holm <sunny@sunbase.org> writes:\n>\n>> git_object(): Check if $type is defined before chomping it. This removes\n>> a Perl warning in the server error log:\n>>\n>>   gitweb.cgi: Use of uninitialized value $type in scalar chomp at\n>>   [...]/gitweb.cgi line 7579., referer: [...]\n>>\n>> when trying to access a non-existing commit, for example:\n>>\n>>   http://HOST/?p=PROJECT.git;a=commit;h=NON_EXISTING_COMMIT\n>\n> Thanks.  The analysis and description of the issue and the fix both\n> make sense to me.\n\nWith this, you would then do\n\n print $cgi->redirect(-uri => href(action=>$type, ...);\n\nbut then href treats $param{action} that is an undef as if it does not\neven exist,\nso the effect will not be felt during the invocation of this request.\n\nI am not sure what happens to a request that lacks action (mapped to 'a'\nparameter) that results from this redirect, though.  Would that eventually\nhit dispatch where if (!defined $action) would cause it to say \"Object does\nnot exist\"?\n\nIn any case, this looks like a strict improvement. Thanks again.\n\n>> Signed-off-by: Øyvind A. Holm <sunny@sunbase.org>\n>> ---\n>>  gitweb/gitweb.perl | 2 +-\n>>  1 file changed, 1 insertion(+), 1 deletion(-)\n>>\n>> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl\n>> index 7a5b23a..05d7910 100755\n>> --- a/gitweb/gitweb.perl\n>> +++ b/gitweb/gitweb.perl\n>> @@ -7576,7 +7576,7 @@ sub git_object {\n>>                       git_cmd(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'\n>>                       or die_error(404, \"Object does not exist\");\n>>               $type = <$fd>;\n>> -             chomp $type;\n>> +             defined $type && chomp $type;\n>>               close $fd\n>>                       or die_error(404, \"Object does not exist\");\n>\n"}]}