summaryrefslogtreecommitdiff
blob: 1f6417b58732deb0a3f8aee1613e7c9ed0cea8f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/python

# Ripped from HP and updated from Debian
# Update by Gentoo to support unicode output

#
# Copyright (c) 2004 Hewlett-Packard Development Company, L.P.
#	David Mosberger <davidm@hpl.hp.com>
#
# Scan standard input for GCC warning messages that are likely to
# source of real 64-bit problems.  In particular, see whether there
# are any implicitly declared functions whose return values are later
# interpreted as pointers.  Those are almost guaranteed to cause
# crashes.
#

from __future__ import print_function

import re
import sys

implicit_pattern = re.compile("([^:]*):(\d+): warning: implicit declaration "
                              + "of function [`']([^']*)'")
pointer_pattern = (
    "([^:]*):(\d+): warning: "
    + "("
    +  "(assignment"
    +  "|initialization"
    +  "|return"
    +  "|passing arg \d+ of `[^']*'"
    +  "|passing arg \d+ of pointer to function"
    +  ") makes pointer from integer without a cast"
    + "|"
    + "cast to pointer from integer of different size)")

if sys.hexversion < 0x3000000:
    pointer_pattern = unicode(pointer_pattern, encoding='utf_8')
    unicode_quote_open = unicode('\xE2\x80\x98', encoding='utf_8')
    unicode_quote_close = unicode('\xE2\x80\x99', encoding='utf_8')
    out = sys.stdout
else:
    unicode_quote_open = '\u2018'
    unicode_quote_close = '\u2019'
    out = sys.stdout.buffer
pointer_pattern = re.compile(pointer_pattern)

last_implicit_filename = ""
last_implicit_linenum = -1
last_implicit_func = ""

def write(msg):
    out.write(msg.encode('utf_8', 'backslashreplace'))

while True:
    if sys.hexversion >= 0x3000000:
        line = sys.stdin.buffer.readline().decode('utf_8', 'replace')
    else:
        line = unicode(sys.stdin.readline(),
            encoding='utf_8', errors='replace')
    if not line:
        break
    # translate unicode open/close quotes to ascii ones
    line = line.replace(unicode_quote_open, "`")
    line = line.replace(unicode_quote_close, "'")
    m = implicit_pattern.match(line)
    if m:
        last_implicit_filename = m.group(1)
        last_implicit_linenum = int(m.group(2))
        last_implicit_func = m.group(3)
    else:
        m = pointer_pattern.match(line)
        if m:
            pointer_filename = m.group(1)
            pointer_linenum = int(m.group(2))
            if (last_implicit_filename == pointer_filename
                and last_implicit_linenum == pointer_linenum):
                write("Function `%s' implicitly converted to pointer at " \
                      "%s:%d\n" % (last_implicit_func,
                                   last_implicit_filename,
                                   last_implicit_linenum))