View Issue Details

IDProjectCategoryView StatusLast Update
0030672FPCRTLpublic2016-11-18 13:23
ReportersilvioprogAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product Version3.1.1Product Build 
Target Version3.2.0Fixed in Version3.1.1 
Summary0030672: Possible fix on getopts unit?
DescriptionHello,

I've used getopts in a code compiled with Delphi, that showed me a warning:

H2077 Value assigned to 'Internal_getopt' never used

after apply this attached patch the warning was solved, but I'm not sure if it is a possible bug.

Can you check if it really solve a possible bug?

Thank you!
TagsNo tags attached.
Fixed in Revision34884
FPCOldBugId
FPCTarget
Attached Files
  • 0001-getopts-fix-from-Silvio-Clecio.patch (588 bytes)
    From f6bc51856bdad8e06df6dfe3c8807113a8bd677a Mon Sep 17 00:00:00 2001
    From: silvioprog <silvioprog@gmail.com>
    Date: Fri, 30 Sep 2016 17:05:53 -0300
    Subject: [PATCH] * getopts fix from Silvio Clecio
    
    ---
     rtl/inc/getopts.pp | 1 +
     1 file changed, 1 insertion(+)
    
    diff --git a/rtl/inc/getopts.pp b/rtl/inc/getopts.pp
    index 1b4f030..8447630 100644
    --- a/rtl/inc/getopts.pp
    +++ b/rtl/inc/getopts.pp
    @@ -351,6 +351,7 @@ begin
               nextchar:=0;
               inc(optind);
               Internal_getopt:='?';
    +          exit;
             end;
            if pfound<>nil then
             begin
    -- 
    2.7.4
    
    

Activities

silvioprog

2016-09-30 22:14

reporter  

0001-getopts-fix-from-Silvio-Clecio.patch (588 bytes)
From f6bc51856bdad8e06df6dfe3c8807113a8bd677a Mon Sep 17 00:00:00 2001
From: silvioprog <silvioprog@gmail.com>
Date: Fri, 30 Sep 2016 17:05:53 -0300
Subject: [PATCH] * getopts fix from Silvio Clecio

---
 rtl/inc/getopts.pp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/rtl/inc/getopts.pp b/rtl/inc/getopts.pp
index 1b4f030..8447630 100644
--- a/rtl/inc/getopts.pp
+++ b/rtl/inc/getopts.pp
@@ -351,6 +351,7 @@ begin
           nextchar:=0;
           inc(optind);
           Internal_getopt:='?';
+          exit;
         end;
        if pfound<>nil then
         begin
-- 
2.7.4

Thaddy de Koning

2016-10-15 11:40

reporter   ~0095169

Last edited: 2016-10-15 12:45

View 11 revisions

Could it be that Delphi does not recognize the function name as result?
The patch is possibly not correct.
Why?
The {$MODESWITCH RESULT-} is active or actually better {$MODESWITCH RESULT} is not activated.
.

The code is compiled in mode fpc and internal_getopt is the function name.
In delphi mode it should be result :='?';

Hence Delphi throws a hint, but in mode objfpc it simply means the function result := '?'

Applying the patch will break the code since the function result is missing ....

And since it is the function result and not a local var it is definitely used.

For reference, the code is in
Function Internal_getopt (Var Optstring : string;LongOpts : POption;
                          LongInd : pointer;Long_only : boolean ) : char;

[edit]
I am not quite sure this is the complete issue after some thought.

Michael Van Canneyt

2016-11-13 12:03

administrator   ~0095822

It is indeed a bug. The original code stems from a C implementation, where
return n
should have been translated by
internal_getopt:=n;
exit;

Clearly, this one missed the exit.

silvioprog

2016-11-18 13:23

reporter   ~0095990

> should have been translated by
> internal_getopt:=n;
> exit;

Exactly, or:

exit(n);

just cosmetic, it is already working fine.

Thank you! :-)

Issue History

Date Modified Username Field Change
2016-09-30 22:14 silvioprog New Issue
2016-09-30 22:14 silvioprog File Added: 0001-getopts-fix-from-Silvio-Clecio.patch
2016-10-14 11:16 Michael Van Canneyt Assigned To => Michael Van Canneyt
2016-10-14 11:16 Michael Van Canneyt Status new => assigned
2016-10-15 11:40 Thaddy de Koning Note Added: 0095169
2016-10-15 11:41 Thaddy de Koning Note Edited: 0095169 View Revisions
2016-10-15 11:43 Thaddy de Koning Note Edited: 0095169 View Revisions
2016-10-15 11:44 Thaddy de Koning Note Edited: 0095169 View Revisions
2016-10-15 11:46 Thaddy de Koning Note Edited: 0095169 View Revisions
2016-10-15 11:47 Thaddy de Koning Note Edited: 0095169 View Revisions
2016-10-15 11:48 Thaddy de Koning Note Edited: 0095169 View Revisions
2016-10-15 11:49 Thaddy de Koning Note Edited: 0095169 View Revisions
2016-10-15 11:57 Thaddy de Koning Note Edited: 0095169 View Revisions
2016-10-15 12:44 Thaddy de Koning Note Edited: 0095169 View Revisions
2016-10-15 12:45 Thaddy de Koning Note Edited: 0095169 View Revisions
2016-11-13 12:03 Michael Van Canneyt Fixed in Revision => 34884
2016-11-13 12:03 Michael Van Canneyt Note Added: 0095822
2016-11-13 12:03 Michael Van Canneyt Status assigned => resolved
2016-11-13 12:03 Michael Van Canneyt Fixed in Version => 3.1.1
2016-11-13 12:03 Michael Van Canneyt Resolution open => fixed
2016-11-13 12:03 Michael Van Canneyt Target Version => 3.2.0
2016-11-18 13:23 silvioprog Note Added: 0095990
2016-11-18 13:23 silvioprog Status resolved => closed