[PATCH] cast: fix warning position in cast_pseudo()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The function cast_pseudo() can issues warnings about non size-preserving
integer <-> pointer casts. The file:line:column position of these warnings
is taken from the destination type but this position is the one where the
type is declared (or where the symbol associated with this type is defined)
which may or may not be related to the position of the cast.

Fix this by using the current position instead (which should hold the
position of the cast).

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 linearize.c                   | 5 +++--
 validation/cast-kinds-check.c | 4 ++--
 validation/cast-weirds.c      | 4 ++--
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/linearize.c b/linearize.c
index eeef0ba73..ce68ba10a 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1313,6 +1313,7 @@ static int get_cast_opcode(struct symbol *dst, struct symbol *src)
 
 static pseudo_t cast_pseudo(struct entrypoint *ep, pseudo_t src, struct symbol *from, struct symbol *to)
 {
+	const struct position pos = current_pos;
 	pseudo_t result;
 	struct instruction *insn;
 	int opcode;
@@ -1333,7 +1334,7 @@ static pseudo_t cast_pseudo(struct entrypoint *ep, pseudo_t src, struct symbol *
 		if (src == value_pseudo(0))
 			break;
 		if (Wint_to_pointer_cast)
-			warning(to->pos, "non size-preserving integer to pointer cast");
+			warning(pos, "non size-preserving integer to pointer cast");
 		src = cast_pseudo(ep, src, from, size_t_ctype);
 		from = size_t_ctype;
 		break;
@@ -1341,7 +1342,7 @@ static pseudo_t cast_pseudo(struct entrypoint *ep, pseudo_t src, struct symbol *
 		if (from->bit_size == to->bit_size)
 			break;
 		if (Wpointer_to_int_cast)
-			warning(to->pos, "non size-preserving pointer to integer cast");
+			warning(pos, "non size-preserving pointer to integer cast");
 		src = cast_pseudo(ep, src, from, size_t_ctype);
 		return cast_pseudo(ep, src, size_t_ctype, to);
 	case OP_BADOP:
diff --git a/validation/cast-kinds-check.c b/validation/cast-kinds-check.c
index b50ddd244..7eb1ca1c8 100644
--- a/validation/cast-kinds-check.c
+++ b/validation/cast-kinds-check.c
@@ -13,7 +13,7 @@ optim/cast-kinds.c:12:48: warning: cast drops bits
 optim/cast-kinds.c:13:50: warning: cast drops bits
 optim/cast-kinds.c:14:49: warning: cast drops bits
 optim/cast-kinds.c:15:48: warning: cast drops bits
-optim/cast-kinds.c:37:42: warning: non size-preserving integer to pointer cast
-optim/cast-kinds.c:38:44: warning: non size-preserving integer to pointer cast
+optim/cast-kinds.c:37:48: warning: non size-preserving integer to pointer cast
+optim/cast-kinds.c:38:50: warning: non size-preserving integer to pointer cast
  * check-error-end
  */
diff --git a/validation/cast-weirds.c b/validation/cast-weirds.c
index 01ccc473f..7d0288829 100644
--- a/validation/cast-weirds.c
+++ b/validation/cast-weirds.c
@@ -12,7 +12,7 @@ static void * uint_2_vptr(uint a) { return (void *)a; }
  * check-command: sparse -m64 $file
  *
  * check-error-start
-cast-weirds.c:4:42: warning: non size-preserving integer to pointer cast
-cast-weirds.c:5:44: warning: non size-preserving integer to pointer cast
+cast-weirds.c:4:48: warning: non size-preserving integer to pointer cast
+cast-weirds.c:5:50: warning: non size-preserving integer to pointer cast
  * check-error-end
  */
-- 
2.18.0

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux