Skip to content

Commit cf025df

Browse files
committed
Fixed several issues reported by PVS Studio static analyzer
1 parent ee21d94 commit cf025df

File tree

4 files changed

+32
-40
lines changed

4 files changed

+32
-40
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*******************************************************************************
44

55
=== 1.0.15 ===
6+
* Fixed several issues reported by PVS Studio static analyzer.
67
* Fixed syntax error in C interface, covered with tests.
78
* Bugfix in horizontal summing functions (invalid register clobber list).
89
* Some AMD-related optimizations.

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ Current set of functions provided:
3232
* Interpolation functions;
3333
* Some set of function to work with 3D mathematics.
3434

35-
Supported platforms
36-
======
35+
## Supported platforms
3736

3837
The build and correct unit test execution has been confirmed for following platforms:
3938
* FreeBSD
@@ -42,8 +41,7 @@ The build and correct unit test execution has been confirmed for following platf
4241
* Windows 32-bit
4342
* Windows 64-bit
4443

45-
Supported architectures
46-
======
44+
## Supported architectures
4745

4846
The support of following list of hardware architectures has been implemented:
4947
* i386 (32-bit) - full support.
@@ -55,16 +53,14 @@ The support of following list of hardware architectures has been implemented:
5553
For all other architectures the generic implementation of algorithms is used, without any
5654
architecture-specific optimizations.
5755

58-
Requirements
59-
======
56+
## Requirements
6057

6158
The following packages need to be installed for building:
6259

6360
* gcc >= 4.9
6461
* make >= 4.0
6562

66-
Building
67-
======
63+
## Building
6864

6965
To build the library, perform the following commands:
7066

@@ -203,4 +199,6 @@ int main(int argc, const char **argv)
203199
204200
```
205201

202+
## SAST Tools
206203

204+
* [PVS-Studio](https://pvs-studio.com/en/pvs-studio/?utm_source=website&utm_medium=github&utm_campaign=open_source) - static analyzer for C, C++, C#, and Java code.

include/private/dsp/arch/generic/context.h

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3-
* (C) 2020 Vladimir Sadovnikov <[email protected]>
2+
* Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
3+
* (C) 2023 Vladimir Sadovnikov <[email protected]>
44
*
55
* This file is part of lsp-dsp-lib
66
* Created on: 31 мар. 2020 г.
@@ -44,28 +44,32 @@ namespace lsp
4444

4545
dsp::info_t *info()
4646
{
47-
size_t size =
48-
sizeof(dsp::info_t) +
47+
size_t szof_dsp_info = sizeof(dsp::info_t);
48+
size_t size =
49+
szof_dsp_info +
4950
strlen(ARCH_STRING) + 1 +
5051
strlen("native cpu") + 1 +
5152
strlen("unknown") + 1;
5253

53-
dsp::info_t *res = reinterpret_cast<dsp::info_t *>(malloc(size));
54-
if (res == NULL)
55-
return res;
54+
uint8_t *ptr = static_cast<uint8_t *>(malloc(size));
55+
if (ptr == NULL)
56+
return NULL;
5657

57-
char *text = reinterpret_cast<char *>(&res[1]);
58-
res->arch = text;
59-
text = stpcpy(text, ARCH_STRING) + 1;
60-
res->cpu = text;
61-
text = stpcpy(text, "native cpu") + 1;
62-
res->model = text;
63-
text = stpcpy(text, "unknown");
64-
res->features = text; // Empty string
58+
dsp::info_t *res = reinterpret_cast<dsp::info_t *>(ptr);
59+
ptr += szof_dsp_info;
60+
61+
char *text = reinterpret_cast<char *>(ptr);
62+
res->arch = text;
63+
text = stpcpy(text, ARCH_STRING) + 1;
64+
res->cpu = text;
65+
text = stpcpy(text, "native cpu") + 1;
66+
res->model = text;
67+
text = stpcpy(text, "unknown");
68+
res->features = text; // Empty string
6569

6670
return res;
6771
}
68-
}
69-
}
72+
} /* namespace generic */
73+
} /* namespace lsp */
7074

7175
#endif /* PRIVATE_DSP_ARCH_GENERIC_CONTEXT_H_ */

src/main/x86/x86.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3-
* (C) 2020 Vladimir Sadovnikov <[email protected]>
2+
* Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
3+
* (C) 2023 Vladimir Sadovnikov <[email protected]>
44
*
55
* This file is part of lsp-dsp-lib
66
* Created on: 31 мар. 2020 г.
@@ -521,23 +521,12 @@
521521
return true;
522522
}
523523
break;
524+
524525
case FEAT_FAST_AVX:
525-
if (f->vendor == CPU_VENDOR_INTEL) // Any Intel CPU is good enough with AVX
526-
return true;
527-
// Only starting with ZEN 1 architecture AMD's implementation of AVX is fast enough
528-
if ((f->vendor == CPU_VENDOR_AMD) || (f->vendor == CPU_VENDOR_HYGON))
529-
{
530-
if (f->family < AMD_FAMILY_ZEN_1_2)
531-
return false;
532-
if (f->family == AMD_FAMILY_DHYANA)
533-
return false;
534-
return true;
535-
}
536-
break;
537526
case FEAT_FAST_FMA3:
538527
if (f->vendor == CPU_VENDOR_INTEL) // Any Intel CPU is good enough with AVX
539528
return true;
540-
// Starting with ZEN 2 FMA3 operations are fast enough on AMD
529+
// Only starting with ZEN 1 architecture AMD's implementation of AVX is fast enough
541530
if ((f->vendor == CPU_VENDOR_AMD) || (f->vendor == CPU_VENDOR_HYGON))
542531
{
543532
if (f->family < AMD_FAMILY_ZEN_1_2)

0 commit comments

Comments
 (0)