Repository: bitcoin/bitcoin
File: contrib/devtools/test-security-check.py (Python)

Code before:
#!/usr/bin/env python3
# Copyright (c) 2015-2022 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
'''
Test script for security-check.py
'''
import lief
import os
import subprocess
import unittest

from utils import determine_wellknown_cmd

def write_testcode(filename):
    with open(filename, 'w', encoding="utf8") as f:
        f.write('''
    #include <stdio.h>
    int main()
    {
        printf("the quick brown fox jumps over the lazy god\\n");
        return 0;
    }
    ''')

def clean_files(source, executable):
    os.remove(source)
    os.remove(executable)

def env_flags() -> list[str]:
    # This should behave the same as AC_TRY_LINK, so arrange well-known flags
    # in the same order as autoconf would.
    #
    # See the definitions for ac_link in autoconf's lib/autoconf/c.m4 file for
    # reference.
    flags: list[str] = []
    for var in ['CFLAGS', 'CPPFLAGS', 'LDFLAGS']:
        flags += filter(None, os.environ.get(var, '').split(' '))
    return flags

def call_security_check(cc: str, source: str, executable: str, options) -> tuple:
    subprocess.run([*cc,source,'-o',executable] + env_flags() + options, check=True)
    p = subprocess.run([os.path.join(os.path.dirname(__file__), 'security-check.py'), executable], stdout=subprocess.PIPE, text=True)
    return (p.returncode, p.stdout.rstrip())

def get_arch(cc, source, executable):

Review comment (bug):
```suggestion
        std::printf("the quick brown fox jumps over the lazy god\\n");
```

Otherwise, it fails:
```
test1.cpp:5:21: warning: missing terminating " character
    5 |         std::printf("the quick brown fox jumps over the lazy god
      |                     ^
test1.cpp:5:21: error: missing terminating " character
    5 |         std::printf("the quick brown fox jumps over the lazy god
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test1.cpp:6:1: warning: missing terminating " character
    6 | ");
      | ^
test1.cpp:6:1: error: missing terminating " character
    6 | ");
      | ^~~
test1.cpp: In function 'int main()':
test1.cpp:7:9: error: expected primary-expression before 'return'
    7 |         return 0;
      |         ^~~~~~
```

Code after:
#!/usr/bin/env python3
# Copyright (c) 2015-2022 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
'''
Test script for security-check.py
'''
import lief
import os
import subprocess
import unittest

from utils import determine_wellknown_cmd

def write_testcode(filename):
    with open(filename, 'w', encoding="utf8") as f:
        f.write('''
    #include <cstdio>
    int main()
    {
        std::printf("the quick brown fox jumps over the lazy god\\n");
        return 0;
    }
    ''')

def clean_files(source, executable):
    os.remove(source)
    os.remove(executable)

def env_flags() -> list[str]:
    # This should behave the same as AC_TRY_LINK, so arrange well-known flags
    # in the same order as autoconf would.
    #
    # See the definitions for ac_link in autoconf's lib/autoconf/c.m4 file for
    # reference.
    flags: list[str] = []
    for var in ['CXXFLAGS', 'CPPFLAGS', 'LDFLAGS']:
        flags += filter(None, os.environ.get(var, '').split(' '))
    return flags

def call_security_check(cxx: str, source: str, executable: str, options) -> tuple:
    subprocess.run([*cxx,source,'-o',executable] + env_flags() + options, check=True)
    p = subprocess.run([os.path.join(os.path.dirname(__file__), 'security-check.py'), executable], stdout=subprocess.PIPE, text=True)
    return (p.returncode, p.stdout.rstrip())

def get_arch(cxx, source, executable):