The following issues were found
tests/misc/sys_atexit.py
6 issues
Line: 3
Column: 1
# test sys.atexit() function
import usys
try:
usys.atexit
except AttributeError:
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 9
Column: 5
usys.atexit
except AttributeError:
print("SKIP")
raise SystemExit
some_var = None
def do_at_exit():
Reported by Pylint.
Line: 1
Column: 1
# test sys.atexit() function
import usys
try:
usys.atexit
except AttributeError:
print("SKIP")
raise SystemExit
Reported by Pylint.
Line: 11
Column: 1
print("SKIP")
raise SystemExit
some_var = None
def do_at_exit():
print("done at exit:", some_var)
Reported by Pylint.
Line: 14
Column: 1
some_var = None
def do_at_exit():
print("done at exit:", some_var)
usys.atexit(do_at_exit)
Reported by Pylint.
Line: 20
Column: 1
usys.atexit(do_at_exit)
some_var = "ok"
print("done before exit")
Reported by Pylint.
tests/basics/closure_namedarg.py
6 issues
Line: 1
Column: 1
# test passing named arg to closed-over function
def f():
x = 1
def g(z):
print(x, z)
return g
f()(z=42)
Reported by Pylint.
Line: 3
Column: 1
# test passing named arg to closed-over function
def f():
x = 1
def g(z):
print(x, z)
return g
f()(z=42)
Reported by Pylint.
Line: 3
Column: 1
# test passing named arg to closed-over function
def f():
x = 1
def g(z):
print(x, z)
return g
f()(z=42)
Reported by Pylint.
Line: 4
Column: 5
# test passing named arg to closed-over function
def f():
x = 1
def g(z):
print(x, z)
return g
f()(z=42)
Reported by Pylint.
Line: 5
Column: 5
def f():
x = 1
def g(z):
print(x, z)
return g
f()(z=42)
Reported by Pylint.
Line: 5
Column: 5
def f():
x = 1
def g(z):
print(x, z)
return g
f()(z=42)
Reported by Pylint.
tests/internal_bench/func_args-3.1-kw_1.py
6 issues
Line: 4
Column: 10
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
Reported by Pylint.
Line: 1
Column: 1
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
Reported by Pylint.
Line: 1
Column: 1
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
Reported by Pylint.
Line: 4
Column: 1
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
Reported by Pylint.
Line: 4
Column: 1
import bench
def func(a):
pass
def test(num):
for i in iter(range(num)):
Reported by Pylint.
Line: 8
Column: 1
pass
def test(num):
for i in iter(range(num)):
func(a=i)
bench.run(test)
Reported by Pylint.
tests/cpydiff/syntax_spaces.py
6 issues
Line: 8
Column: 11
workaround: Unknown
"""
try:
print(eval("1and 0"))
except SyntaxError:
print("Should have worked")
try:
print(eval("1or 0"))
except SyntaxError:
Reported by Pylint.
Line: 8
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval
workaround: Unknown
"""
try:
print(eval("1and 0"))
except SyntaxError:
print("Should have worked")
try:
print(eval("1or 0"))
except SyntaxError:
Reported by Bandit.
Line: 12
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval
except SyntaxError:
print("Should have worked")
try:
print(eval("1or 0"))
except SyntaxError:
print("Should have worked")
try:
print(eval("1if 1else 0"))
except SyntaxError:
Reported by Bandit.
Line: 12
Column: 11
except SyntaxError:
print("Should have worked")
try:
print(eval("1or 0"))
except SyntaxError:
print("Should have worked")
try:
print(eval("1if 1else 0"))
except SyntaxError:
Reported by Pylint.
Line: 16
Column: 11
except SyntaxError:
print("Should have worked")
try:
print(eval("1if 1else 0"))
except SyntaxError:
print("Should have worked")
Reported by Pylint.
Line: 16
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval
except SyntaxError:
print("Should have worked")
try:
print(eval("1if 1else 0"))
except SyntaxError:
print("Should have worked")
Reported by Bandit.
tests/basics/class_reverse_op.py
6 issues
Line: 1
Column: 1
class A:
def __init__(self, v):
self.v = v
def __add__(self, o):
if isinstance(o, A):
return A(self.v + o.v)
return A(self.v + o)
Reported by Pylint.
Line: 1
Column: 1
class A:
def __init__(self, v):
self.v = v
def __add__(self, o):
if isinstance(o, A):
return A(self.v + o.v)
return A(self.v + o)
Reported by Pylint.
Line: 1
Column: 1
class A:
def __init__(self, v):
self.v = v
def __add__(self, o):
if isinstance(o, A):
return A(self.v + o.v)
return A(self.v + o)
Reported by Pylint.
Line: 4
Column: 9
class A:
def __init__(self, v):
self.v = v
def __add__(self, o):
if isinstance(o, A):
return A(self.v + o.v)
return A(self.v + o)
Reported by Pylint.
Line: 6
Column: 5
def __init__(self, v):
self.v = v
def __add__(self, o):
if isinstance(o, A):
return A(self.v + o.v)
return A(self.v + o)
def __radd__(self, o):
Reported by Pylint.
Line: 11
Column: 5
return A(self.v + o.v)
return A(self.v + o)
def __radd__(self, o):
return A(self.v + o)
def __repr__(self):
return "A({})".format(self.v)
Reported by Pylint.
lib/littlefs/lfs1_util.h
6 issues
Line: 147
CWE codes:
758
return __builtin_bswap32(a);
#else
return (((uint8_t*)&a)[0] << 0) |
(((uint8_t*)&a)[1] << 8) |
(((uint8_t*)&a)[2] << 16) |
(((uint8_t*)&a)[3] << 24);
#endif
}
Reported by Cppcheck.
Line: 147
CWE codes:
758
return __builtin_bswap32(a);
#else
return (((uint8_t*)&a)[0] << 0) |
(((uint8_t*)&a)[1] << 8) |
(((uint8_t*)&a)[2] << 16) |
(((uint8_t*)&a)[3] << 24);
#endif
}
Reported by Cppcheck.
Line: 148
CWE codes:
758
#else
return (((uint8_t*)&a)[0] << 0) |
(((uint8_t*)&a)[1] << 8) |
(((uint8_t*)&a)[2] << 16) |
(((uint8_t*)&a)[3] << 24);
#endif
}
// Convert to 32-bit little-endian from native order
Reported by Cppcheck.
Line: 148
CWE codes:
758
#else
return (((uint8_t*)&a)[0] << 0) |
(((uint8_t*)&a)[1] << 8) |
(((uint8_t*)&a)[2] << 16) |
(((uint8_t*)&a)[3] << 24);
#endif
}
// Convert to 32-bit little-endian from native order
Reported by Cppcheck.
Line: 149
CWE codes:
758
return (((uint8_t*)&a)[0] << 0) |
(((uint8_t*)&a)[1] << 8) |
(((uint8_t*)&a)[2] << 16) |
(((uint8_t*)&a)[3] << 24);
#endif
}
// Convert to 32-bit little-endian from native order
static inline uint32_t lfs1_tole32(uint32_t a) {
Reported by Cppcheck.
Line: 149
CWE codes:
758
return (((uint8_t*)&a)[0] << 0) |
(((uint8_t*)&a)[1] << 8) |
(((uint8_t*)&a)[2] << 16) |
(((uint8_t*)&a)[3] << 24);
#endif
}
// Convert to 32-bit little-endian from native order
static inline uint32_t lfs1_tole32(uint32_t a) {
Reported by Cppcheck.
ports/stm32/flashbdev.c
6 issues
Line: 160
CWE codes:
570
return 0;
case BDEV_IOCTL_NUM_BLOCKS:
return FLASH_MEM_SEG1_NUM_BLOCKS + FLASH_MEM_SEG2_NUM_BLOCKS;
case BDEV_IOCTL_IRQ_HANDLER:
flash_bdev_irq_handler();
return 0;
Reported by Cppcheck.
Line: 185
CWE codes:
570
uint32_t flash_sector_start;
uint32_t flash_sector_size;
int32_t flash_sector_id = flash_get_sector_info(flash_addr, &flash_sector_start, &flash_sector_size);
if (flash_sector_size > FLASH_SECTOR_SIZE_MAX) {
flash_sector_size = FLASH_SECTOR_SIZE_MAX;
}
if (flash_cache_sector_id != flash_sector_id) {
flash_bdev_ioctl(BDEV_IOCTL_SYNC, 0);
memcpy((void *)CACHE_MEM_START_ADDR, (const void *)flash_sector_start, flash_sector_size);
Reported by Cppcheck.
Line: 186
CWE codes:
570
uint32_t flash_sector_size;
int32_t flash_sector_id = flash_get_sector_info(flash_addr, &flash_sector_start, &flash_sector_size);
if (flash_sector_size > FLASH_SECTOR_SIZE_MAX) {
flash_sector_size = FLASH_SECTOR_SIZE_MAX;
}
if (flash_cache_sector_id != flash_sector_id) {
flash_bdev_ioctl(BDEV_IOCTL_SYNC, 0);
memcpy((void *)CACHE_MEM_START_ADDR, (const void *)flash_sector_start, flash_sector_size);
flash_cache_sector_id = flash_sector_id;
Reported by Cppcheck.
Line: 214
CWE codes:
570
}
static uint32_t convert_block_to_flash_addr(uint32_t block) {
if (block < FLASH_MEM_SEG1_NUM_BLOCKS) {
return FLASH_MEM_SEG1_START_ADDR + block * FLASH_BLOCK_SIZE;
}
if (block < FLASH_MEM_SEG1_NUM_BLOCKS + FLASH_MEM_SEG2_NUM_BLOCKS) {
return FLASH_MEM_SEG2_START_ADDR + (block - FLASH_MEM_SEG1_NUM_BLOCKS) * FLASH_BLOCK_SIZE;
}
Reported by Cppcheck.
Line: 217
CWE codes:
570
if (block < FLASH_MEM_SEG1_NUM_BLOCKS) {
return FLASH_MEM_SEG1_START_ADDR + block * FLASH_BLOCK_SIZE;
}
if (block < FLASH_MEM_SEG1_NUM_BLOCKS + FLASH_MEM_SEG2_NUM_BLOCKS) {
return FLASH_MEM_SEG2_START_ADDR + (block - FLASH_MEM_SEG1_NUM_BLOCKS) * FLASH_BLOCK_SIZE;
}
// can add more flash segments here if needed, following above pattern
// bad block
Reported by Cppcheck.
Line: 218
CWE codes:
570
return FLASH_MEM_SEG1_START_ADDR + block * FLASH_BLOCK_SIZE;
}
if (block < FLASH_MEM_SEG1_NUM_BLOCKS + FLASH_MEM_SEG2_NUM_BLOCKS) {
return FLASH_MEM_SEG2_START_ADDR + (block - FLASH_MEM_SEG1_NUM_BLOCKS) * FLASH_BLOCK_SIZE;
}
// can add more flash segments here if needed, following above pattern
// bad block
return -1;
Reported by Cppcheck.
lib/littlefs/lfs2.c
6 issues
Line: 2074
CWE codes:
562
// ourselves into littlefs to catch this
cwd.type = 0;
cwd.id = 0;
lfs2->mlist = &cwd;
lfs2_pair_tole32(dir.pair);
err = lfs2_dir_commit(lfs2, &pred, LFS2_MKATTRS(
{LFS2_MKTAG(LFS2_TYPE_SOFTTAIL, 0x3ff, 8), dir.pair}));
lfs2_pair_fromle32(dir.pair);
Reported by Cppcheck.
Line: 3217
CWE codes:
562
// commit (if predecessor is child)
dir.type = 0;
dir.id = 0;
lfs2->mlist = &dir;
}
// delete the entry
err = lfs2_dir_commit(lfs2, &cwd, LFS2_MKATTRS(
{LFS2_MKTAG(LFS2_TYPE_DELETE, lfs2_tag_id(tag), 0), NULL}));
Reported by Cppcheck.
Line: 3323
CWE codes:
562
// commit (if predecessor is child)
prevdir.type = 0;
prevdir.id = 0;
lfs2->mlist = &prevdir;
}
if (!samepair) {
lfs2_fs_prepmove(lfs2, newoldid, oldcwd.pair);
}
Reported by Cppcheck.
Line: 1848
CWE codes:
476
lfs2_mdir_t olddir = *dir;
bool hasdelete = false;
for (int i = 0; i < attrcount; i++) {
if (lfs2_tag_type3(attrs[i].tag) == LFS2_TYPE_CREATE) {
dir->count += 1;
} else if (lfs2_tag_type3(attrs[i].tag) == LFS2_TYPE_DELETE) {
LFS2_ASSERT(dir->count > 0);
dir->count -= 1;
hasdelete = true;
Reported by Cppcheck.
Line: 1850
CWE codes:
476
for (int i = 0; i < attrcount; i++) {
if (lfs2_tag_type3(attrs[i].tag) == LFS2_TYPE_CREATE) {
dir->count += 1;
} else if (lfs2_tag_type3(attrs[i].tag) == LFS2_TYPE_DELETE) {
LFS2_ASSERT(dir->count > 0);
dir->count -= 1;
hasdelete = true;
} else if (lfs2_tag_type1(attrs[i].tag) == LFS2_TYPE_TAIL) {
dir->tail[0] = ((lfs2_block_t*)attrs[i].buffer)[0];
Reported by Cppcheck.
Line: 1854
CWE codes:
476
LFS2_ASSERT(dir->count > 0);
dir->count -= 1;
hasdelete = true;
} else if (lfs2_tag_type1(attrs[i].tag) == LFS2_TYPE_TAIL) {
dir->tail[0] = ((lfs2_block_t*)attrs[i].buffer)[0];
dir->tail[1] = ((lfs2_block_t*)attrs[i].buffer)[1];
dir->split = (lfs2_tag_chunk(attrs[i].tag) & 1);
lfs2_pair_fromle32(dir->tail);
}
Reported by Cppcheck.
tests/basics/class_call.py
6 issues
Line: 16
Column: 11
c2 = C2()
try:
print(c2(1))
except TypeError:
print("TypeError")
Reported by Pylint.
Line: 1
Column: 1
class C1:
def __call__(self, val):
print('call', val)
return 'item'
class C2:
def __getattr__(self, k):
pass
Reported by Pylint.
Line: 1
Column: 1
class C1:
def __call__(self, val):
print('call', val)
return 'item'
class C2:
def __getattr__(self, k):
pass
Reported by Pylint.
Line: 1
Column: 1
class C1:
def __call__(self, val):
print('call', val)
return 'item'
class C2:
def __getattr__(self, k):
pass
Reported by Pylint.
Line: 6
Column: 1
print('call', val)
return 'item'
class C2:
def __getattr__(self, k):
pass
c1 = C1()
Reported by Pylint.
Line: 6
Column: 1
print('call', val)
return 'item'
class C2:
def __getattr__(self, k):
pass
c1 = C1()
Reported by Pylint.
examples/hwapi/soft_pwm.py
6 issues
Line: 1
Column: 1
import utime
from hwconfig import LED
# Using sleep_ms() gives pretty poor PWM resolution and
# brightness control, but we use it in the attempt to
# make this demo portable to even more boards (e.g. to
# those which don't provide sleep_us(), or provide, but
# it's not precise, like would be on non realtime OSes).
Reported by Pylint.
Line: 2
Column: 1
import utime
from hwconfig import LED
# Using sleep_ms() gives pretty poor PWM resolution and
# brightness control, but we use it in the attempt to
# make this demo portable to even more boards (e.g. to
# those which don't provide sleep_us(), or provide, but
# it's not precise, like would be on non realtime OSes).
Reported by Pylint.
Line: 15
Column: 9
# if you're unlucky).
def pwm_cycle(led, duty, cycles):
duty_off = 20 - duty
for i in range(cycles):
if duty:
led.on()
utime.sleep_ms(duty)
if duty_off:
led.off()
Reported by Pylint.
Line: 15
Column: 9
# if you're unlucky).
def pwm_cycle(led, duty, cycles):
duty_off = 20 - duty
for i in range(cycles):
if duty:
led.on()
utime.sleep_ms(duty)
if duty_off:
led.off()
Reported by Pylint.
Line: 1
Column: 1
import utime
from hwconfig import LED
# Using sleep_ms() gives pretty poor PWM resolution and
# brightness control, but we use it in the attempt to
# make this demo portable to even more boards (e.g. to
# those which don't provide sleep_us(), or provide, but
# it's not precise, like would be on non realtime OSes).
Reported by Pylint.
Line: 13
Column: 1
# We otherwise use 20ms period, to make frequency not less
# than 50Hz to avoid visible flickering (you may still see
# if you're unlucky).
def pwm_cycle(led, duty, cycles):
duty_off = 20 - duty
for i in range(cycles):
if duty:
led.on()
utime.sleep_ms(duty)
Reported by Pylint.