[libvirt] [PATCH] virt-aa-helper: fix clang build

Clang complains about wrong argument type: libvirt/src/security/virt-aa-helper.c:174:11: error: absolute value function 'abs' given an argument of type 'long' but has parameter of type 'int' which may cause truncation of value [-Werror,-Wabsolute-value] idx = abs(pos - orig); ^ Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/security/virt-aa-helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 7eeb4ef..14f8afb 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -171,7 +171,7 @@ replace_string(char *orig, const size_t len, const char *oldstr, } tmp[0] = '\0'; - idx = abs(pos - orig); + idx = abs((int)(pos - orig)); /* copy everything up to oldstr */ strncat(tmp, orig, idx); -- 2.8.2

Pavel Hrdina wrote:
Clang complains about wrong argument type:
libvirt/src/security/virt-aa-helper.c:174:11: error: absolute value function 'abs' given an argument of type 'long' but has parameter of type 'int' which may cause truncation of value [-Werror,-Wabsolute-value] idx = abs(pos - orig);
Out of curiosity, why not use labs() here instead of casting?
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> --- src/security/virt-aa-helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 7eeb4ef..14f8afb 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -171,7 +171,7 @@ replace_string(char *orig, const size_t len, const char *oldstr, } tmp[0] = '\0';
- idx = abs(pos - orig); + idx = abs((int)(pos - orig));
/* copy everything up to oldstr */ strncat(tmp, orig, idx); -- 2.8.2
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Roman Bogorodskiy

On Wed, May 11, 2016 at 09:46:23AM +0300, Roman Bogorodskiy wrote:
Pavel Hrdina wrote:
Clang complains about wrong argument type:
libvirt/src/security/virt-aa-helper.c:174:11: error: absolute value function 'abs' given an argument of type 'long' but has parameter of type 'int' which may cause truncation of value [-Werror,-Wabsolute-value] idx = abs(pos - orig);
Out of curiosity, why not use labs() here instead of casting?
Just a random pick from those two possible fixes. It's stored into 'idx' variable which is int and labs() returns long. To use labs() the 'idx' would have to be changed to 'long' or even 'size_t' since it's used only as 'size_t'. If you think that it would be better to use the labs() and change the 'idx' to 'size_t' I can do that. Pavel

Pavel Hrdina wrote:
On Wed, May 11, 2016 at 09:46:23AM +0300, Roman Bogorodskiy wrote:
Pavel Hrdina wrote:
Clang complains about wrong argument type:
libvirt/src/security/virt-aa-helper.c:174:11: error: absolute value function 'abs' given an argument of type 'long' but has parameter of type 'int' which may cause truncation of value [-Werror,-Wabsolute-value] idx = abs(pos - orig);
Out of curiosity, why not use labs() here instead of casting?
Just a random pick from those two possible fixes. It's stored into 'idx' variable which is int and labs() returns long. To use labs() the 'idx' would have to be changed to 'long' or even 'size_t' since it's used only as 'size_t'.
If you think that it would be better to use the labs() and change the 'idx' to 'size_t' I can do that.
Thinking about it, probably using labs() is not quite right, because pointer difference might be not long on all platforms? I'm wondering if it'd make sense to make idx size_t and drop usage of abs() at all, i.e. "idx = (pos > orig) ? pos - orig : orig - pos"?
Pavel
Roman Bogorodskiy

On Wed, May 11, 2016 at 01:30:00PM +0300, Roman Bogorodskiy wrote:
Pavel Hrdina wrote:
On Wed, May 11, 2016 at 09:46:23AM +0300, Roman Bogorodskiy wrote:
Pavel Hrdina wrote:
Clang complains about wrong argument type:
libvirt/src/security/virt-aa-helper.c:174:11: error: absolute value function 'abs' given an argument of type 'long' but has parameter of type 'int' which may cause truncation of value [-Werror,-Wabsolute-value] idx = abs(pos - orig);
Out of curiosity, why not use labs() here instead of casting?
Just a random pick from those two possible fixes. It's stored into 'idx' variable which is int and labs() returns long. To use labs() the 'idx' would have to be changed to 'long' or even 'size_t' since it's used only as 'size_t'.
If you think that it would be better to use the labs() and change the 'idx' to 'size_t' I can do that.
Thinking about it, probably using labs() is not quite right, because pointer difference might be not long on all platforms?
I'm wondering if it'd make sense to make idx size_t and drop usage of abs() at all, i.e. "idx = (pos > orig) ? pos - orig : orig - pos"?
I think using virStringReplace is the nicest solution. :) Jan
Pavel
Roman Bogorodskiy
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (3)
-
Ján Tomko
-
Pavel Hrdina
-
Roman Bogorodskiy