* [PATCH V2 i-g-t 0/3] Expanding the basic vkms features
@ 2018-06-17 0:33 Rodrigo Siqueira
2018-06-17 0:34 ` [PATCH V2 i-g-t 1/3] Avoid truncate string in __igt_lsof_fds Rodrigo Siqueira
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Rodrigo Siqueira @ 2018-06-17 0:33 UTC (permalink / raw)
To: Petri Latvala, Arkadiusz Hiler; +Cc: igt-dev, intel-gfx
During the compilation, some GCC (8.1) warnings are shown. This patchset
address some of the warnings problems.
Changes in v2:
- Better fit the string size for the path requirements
- Improves commit messages
Rodrigo Siqueira (3):
Avoid truncate string in __igt_lsof_fds
Account for NULL character when using strncpy
Move declaration to the top of the code
lib/igt_aux.c | 8 ++++++--
lib/igt_color_encoding.c | 16 ++++++----------
tests/kms_frontbuffer_tracking.c | 2 +-
3 files changed, 13 insertions(+), 13 deletions(-)
--
2.17.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH V2 i-g-t 1/3] Avoid truncate string in __igt_lsof_fds
2018-06-17 0:33 [PATCH V2 i-g-t 0/3] Expanding the basic vkms features Rodrigo Siqueira
@ 2018-06-17 0:34 ` Rodrigo Siqueira
2018-06-17 0:34 ` [PATCH V2 i-g-t 2/3] Account for NULL character when using strncpy Rodrigo Siqueira
2018-06-17 0:34 ` [PATCH V2 i-g-t 3/3] Move declaration to the top of the code Rodrigo Siqueira
2 siblings, 0 replies; 4+ messages in thread
From: Rodrigo Siqueira @ 2018-06-17 0:34 UTC (permalink / raw)
To: Petri Latvala, Arkadiusz Hiler; +Cc: igt-dev, intel-gfx
Note that 'proc_path' parameter in __igt_lsof_fds receives a string
which was initialized with the size of PATH_MAX and the local variable
'path' has the same size, but it also have to append: '/', '\0', and the
directory name. This situation caused the warning described below.
warning: ‘%s’ directive output may be truncated writing up to 255 bytes
into a region of size between 0 and 4095 [-Wformat-truncation=]
snprintf(path, sizeof(path), "%s/%s", proc_path, d->d_name);
note: ‘snprintf’ output between 2 and 4352 bytes into a destination of
size 4096 [..]
This commit fixes this problem by changing the string size passed by
__igt_lsoft to __igt_lsof_fds; basically, the max size for the string is
calculated in a directive and then used to declare the array.
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
---
lib/igt_aux.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index acafb713..1ea52efe 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -48,6 +48,8 @@
#include <sys/utsname.h>
#include <termios.h>
#include <assert.h>
+#include <math.h>
+#include <limits.h>
#include <proc/readproc.h>
#include <libudev.h>
@@ -71,6 +73,8 @@
#include <libgen.h> /* for dirname() */
#endif
+#define MAX_CWD_LEN (unsigned int)(sizeof("/proc//cwd") + ceil(log10(INT_MAX)))
+
/**
* SECTION:igt_aux
* @short_description: Auxiliary libraries and support functions
@@ -1485,7 +1489,7 @@ __igt_lsof(const char *dir)
PROCTAB *proc;
proc_t *proc_info;
- char path[PATH_MAX];
+ char path[MAX_CWD_LEN];
char *name_lnk;
struct stat st;
int state = 0;
--
2.17.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH V2 i-g-t 2/3] Account for NULL character when using strncpy
2018-06-17 0:33 [PATCH V2 i-g-t 0/3] Expanding the basic vkms features Rodrigo Siqueira
2018-06-17 0:34 ` [PATCH V2 i-g-t 1/3] Avoid truncate string in __igt_lsof_fds Rodrigo Siqueira
@ 2018-06-17 0:34 ` Rodrigo Siqueira
2018-06-17 0:34 ` [PATCH V2 i-g-t 3/3] Move declaration to the top of the code Rodrigo Siqueira
2 siblings, 0 replies; 4+ messages in thread
From: Rodrigo Siqueira @ 2018-06-17 0:34 UTC (permalink / raw)
To: Petri Latvala, Arkadiusz Hiler; +Cc: igt-dev, intel-gfx
This patch fix the following gcc warning:
warning: ‘strncpy’ specified bound 32 equals destination size
[-Wstringop-truncation]
strncpy(data->name, name, PARAM_NAME_MAX_SZ);
This error happens due to the '\0' character appended by strncpy. Notice
that reduces by one in the total of bytes to be copied, in this case, is
harmless because the strings received in the parameter already have
'\0'.
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
---
lib/igt_aux.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 1ea52efe..a605becc 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -1244,7 +1244,7 @@ static void igt_save_module_param(const char *name, const char *file_path)
data = calloc(1, sizeof (*data));
igt_assert(data);
- strncpy(data->name, name, PARAM_NAME_MAX_SZ);
+ strncpy(data->name, name, PARAM_NAME_MAX_SZ - 1);
fd = open(file_path, O_RDONLY);
igt_assert(fd >= 0);
--
2.17.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH V2 i-g-t 3/3] Move declaration to the top of the code
2018-06-17 0:33 [PATCH V2 i-g-t 0/3] Expanding the basic vkms features Rodrigo Siqueira
2018-06-17 0:34 ` [PATCH V2 i-g-t 1/3] Avoid truncate string in __igt_lsof_fds Rodrigo Siqueira
2018-06-17 0:34 ` [PATCH V2 i-g-t 2/3] Account for NULL character when using strncpy Rodrigo Siqueira
@ 2018-06-17 0:34 ` Rodrigo Siqueira
2 siblings, 0 replies; 4+ messages in thread
From: Rodrigo Siqueira @ 2018-06-17 0:34 UTC (permalink / raw)
To: Petri Latvala, Arkadiusz Hiler; +Cc: igt-dev, intel-gfx
This patch fix the following gcc warnings:
warning: ISO C90 forbids mixed declarations and code
[-Wdeclaration-after-statement] [..]
igt_color_encoding.c:45:2: warning: ISO C90 forbids mixed declarations
and code [-Wdeclaration-after-statement] [..]
igt_color_encoding.c: In function ‘ycbcr_to_rgb_matrix’:
igt_color_encoding.c:72:2: warning: ISO C90 forbids mixed declarations
and code [-Wdeclaration-after-statement] [..]
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
---
lib/igt_color_encoding.c | 16 ++++++----------
tests/kms_frontbuffer_tracking.c | 2 +-
2 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/lib/igt_color_encoding.c b/lib/igt_color_encoding.c
index b1648a74..1a89bb46 100644
--- a/lib/igt_color_encoding.c
+++ b/lib/igt_color_encoding.c
@@ -36,11 +36,9 @@ static const struct color_encoding color_encodings[IGT_NUM_COLOR_ENCODINGS] = {
static struct igt_mat4 rgb_to_ycbcr_matrix(const struct color_encoding *e)
{
- float kr, kg, kb;
-
- kr = e->kr;
- kb = e->kb;
- kg = 1.0f - kr - kb;
+ float kr = e->kr;
+ float kb = e->kb;
+ float kg = 1.0f - kr - kb;
struct igt_mat4 ret = {
.d[0 * 4 + 0] = kr,
@@ -63,11 +61,9 @@ static struct igt_mat4 rgb_to_ycbcr_matrix(const struct color_encoding *e)
static struct igt_mat4 ycbcr_to_rgb_matrix(const struct color_encoding *e)
{
- float kr, kg, kb;
-
- kr = e->kr;
- kb = e->kb;
- kg = 1.0f - kr - kb;
+ float kr = e->kr;
+ float kb = e->kb;
+ float kg = 1.0f - kr - kb;
struct igt_mat4 ret = {
.d[0 * 4 + 0] = 1.0f,
diff --git a/tests/kms_frontbuffer_tracking.c b/tests/kms_frontbuffer_tracking.c
index 8754cc46..dbb8ba62 100644
--- a/tests/kms_frontbuffer_tracking.c
+++ b/tests/kms_frontbuffer_tracking.c
@@ -1770,8 +1770,8 @@ static void do_status_assertions(int flags)
static void __do_assertions(const struct test_mode *t, int flags,
int line)
{
- flags = adjust_assertion_flags(t, flags);
bool mandatory_sink_crc = t->feature & FEATURE_PSR;
+ flags = adjust_assertion_flags(t, flags);
igt_debug("checking asserts in line %i\n", line);
--
2.17.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-06-17 0:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-17 0:33 [PATCH V2 i-g-t 0/3] Expanding the basic vkms features Rodrigo Siqueira
2018-06-17 0:34 ` [PATCH V2 i-g-t 1/3] Avoid truncate string in __igt_lsof_fds Rodrigo Siqueira
2018-06-17 0:34 ` [PATCH V2 i-g-t 2/3] Account for NULL character when using strncpy Rodrigo Siqueira
2018-06-17 0:34 ` [PATCH V2 i-g-t 3/3] Move declaration to the top of the code Rodrigo Siqueira
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox