Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 4265329
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Fri Mar 23 21:45:32 2018 -0400

    indent to match standard indent.

commit 783518f
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Fri Mar 23 20:21:15 2018 -0400

    clean up the typenames

commit 29b627e
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Fri Mar 23 20:18:04 2018 -0400

    enable feature_hh, warn about %n with non-int modifier.

commit fc4ac81
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Fri Mar 23 15:13:47 2018 -0400

    warn thar %lc, %ls, etc are unsupported.

commit 7e6b433
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Fri Mar 23 13:36:25 2018 -0400

    warn about hh/ll modifier (if not supported)

commit 1943c99
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Fri Mar 23 11:42:41 2018 -0400

    use error facilities for format errors.

commit 7811168
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Thu Mar 22 15:34:21 2018 -0400

    add feature flags to disable c99 enhancements until orca lib is updated.

commit c2149cc
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Thu Mar 22 08:59:10 2018 -0400

    Add printf/scanf format checking [WIP]

    This parses out the xprintf / xscanf format string and compares it with the function arguments.

    enabled via #pragma lint 16.
  • Loading branch information
ksherlock committed Mar 24, 2018
1 parent 5685009 commit 6c1ccc5
Show file tree
Hide file tree
Showing 6 changed files with 872 additions and 5 deletions.
1 change: 1 addition & 0 deletions CCommon.pas
Expand Up @@ -89,6 +89,7 @@ interface
lintNoFnType = $0002; {flag functions with no type}
lintNotPrototyped = $0004; {flag functions with no prototypes}
lintPragmas = $0008; {flag unknown prototypes}
lintPrintf = $0010; {check printf/scanf format flags}

{bit masks for GetLInfo flags}
{----------------------------}
Expand Down
26 changes: 23 additions & 3 deletions Expression.pas
Expand Up @@ -48,7 +48,7 @@

interface

uses CCommon, Table, CGI, Scanner, Symbol, MM;
uses CCommon, Table, CGI, Scanner, Symbol, MM, Printf;

{$segment 'EXP'}

Expand Down Expand Up @@ -2621,7 +2621,9 @@ procedure GenerateCode {tree: tokenPtr};
parameters: parameterPtr; {next prototyped parameter}
pCount: integer; {# of parameters prototyped}
prototype: boolean; {is the function prototyped?}
tp,ltp: tokenPtr; {work pointers}
tp: tokenPtr; {work pointers}
fp, tfp: fmtArgPtr;
fmt: fmt_type;


procedure Reverse;
Expand Down Expand Up @@ -2661,6 +2663,12 @@ procedure GenerateCode {tree: tokenPtr};
prototype := ftype^.prototyped;
parameters := ftype^.parameterList;
pCount := 1;
fmt := fmt_none;
fp := nil;

if ((lint & lintPrintf) <> 0) and fType^.varargs and not indirect then
fmt := FormatClassify(ftree^.id^.name^);

while parameters <> nil do begin {count the prototypes}
pCount := pCount+1;
parameters := parameters^.next;
Expand All @@ -2676,6 +2684,8 @@ procedure GenerateCode {tree: tokenPtr};
Error(85);
end; {if}

tp := parms;

{generate the parameters}
numParms := 0;
lDoDispose := doDispose;
Expand All @@ -2694,6 +2704,13 @@ procedure GenerateCode {tree: tokenPtr};
end {else if}
else
GenerateCode(tp^.middle);
if fmt <> fmt_none then begin
new(tfp);
tfp^.next := fp;
tfp^.tk := tp^.middle;
tfp^.ty := expressionType;
fp := tfp;
end;
if prototype then begin
if pCount = 0 then begin
if parameters <> nil then begin
Expand All @@ -2710,9 +2727,12 @@ procedure GenerateCode {tree: tokenPtr};
Gen0t(pc_bno, UsualUnaryConversions);
numParms := numParms+1;
end; {if}
ltp := tp;
tp := tp^.right;
end; {while}

if fmt <> fmt_none then FormatCheck(fmt, fp);


doDispose := lDoDispose;
if numParms = 0 then
Gen0(pc_nop);
Expand Down

0 comments on commit 6c1ccc5

Please sign in to comment.