Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: remove unused headers-exported functions #9099

Closed
wants to merge 1 commit into from

Conversation

catenacyber
Copy link
Contributor

@catenacyber catenacyber commented Jun 29, 2023

Link to redmine ticket:
None : generic cleaning
https://redmine.openinfosecfoundation.org/issues/4083

Describe changes:

  • remove functions defined in a header and never used (debug, api-completeness, and others)
  • remove double definition of IPPairLock

Python helper script to do this :

import subprocess
import sys
import os

def patchFuncStatic(funcname, cfile, hfile):
    subprocess.run(["sed", "-i", "-e", "/%s/d" % funcname, hfile], stdout=subprocess.PIPE, text=True)
    f = open(cfile, "r")
    f2 = open(cfile+".new", "w")
    writing = True
    for l in f.readlines():
        if funcname in l:
            writing = False
            continue
        if writing:
            f2.write(l)
        elif l.rstrip() == '}':
            writing = True
    f.close()
    f2.close()
    os.rename(cfile+".new", cfile)

def testFuncName(funcret, funcname, hfile):
    result = subprocess.run(["git", "grep", funcname], stdout=subprocess.PIPE, text=True)
    d = dict()
    nbh = 0
    for l in result.stdout.split('\n'):
        hasf = l.split(':')[0]
        if len(hasf) == 0:
            continue
        if hasf == hfile:
            nbh = nbh + 1
            continue
        d[hasf] = d.get(hasf, 0)+1
    if nbh == 1 and len(d) == 1 and list(d.values())[0] == 1:
        print(funcret, funcname, d)
        patchFuncStatic(funcname, list(d.keys())[0], hfile)

f = open(sys.argv[1], "r")
for l in f.readlines():
    if '(' in l:
        ps = l.split('(')[0].split()
        if len(ps) == 2:
            funcret = ps[0]
            funcname = ps[1]
            if funcret != '/*' and funcret != '#define' and funcret != '*':
                if funcname[0] == '*':
                    funcname=funcname[1:]
                testFuncName(funcret,funcname,sys.argv[1])

Needed rebase of #9004

+ remove double definition of IPPairLock
@codecov
Copy link

codecov bot commented Jun 29, 2023

Codecov Report

Merging #9099 (8c1b27c) into master (d822ba5) will increase coverage by 0.17%.
The diff coverage is n/a.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9099      +/-   ##
==========================================
+ Coverage   82.31%   82.48%   +0.17%     
==========================================
  Files         969      969              
  Lines      273722   273174     -548     
==========================================
+ Hits       225307   225336      +29     
+ Misses      48415    47838     -577     
Flag Coverage Δ
fuzzcorpus 64.80% <ø> (+0.20%) ⬆️
suricata-verify 60.77% <ø> (+0.16%) ⬆️
unittests 63.02% <ø> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@suricata-qa
Copy link

WARNING:

field baseline test %
SURI_TLPR1_stats_chk
.app_layer.flow.rfb 221 246 111.31%
.app_layer.tx.rfb 227 246 108.37%
.app_layer.error.rfb.parser 242 1 0.41%

Pipeline 14926

@catenacyber
Copy link
Contributor Author

Rebased in #9255

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants