public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Lifang Xia <lifang_xia@c-sky.com>
To: binutils@sourceware.org
Subject: [PATCH] PR28168: [CSKY] Fix stack overflow in disassembler
Date: Tue, 10 Aug 2021 11:16:57 +0800	[thread overview]
Message-ID: <20210810031657.428-1-lifang_xia@c-sky.com> (raw)

PR 28168:
Stack overflow with a large float. %f is not a goot choice for this.
%f should be replaced with %.7g.

gas/
	* testsuite/gas/csky/pr28168.d: New testcase for PR 28168.
	* testsuite/gas/csky/pr28168.s: Likewise.
	* testsuite/gas/csky/v2_float_part2.d: Following the new format.
	* opcodes/csky-dis.c (csky_output_operand): %.7g replaces %f.
---
 gas/testsuite/gas/csky/pr28168.d        | 12 ++++++++++++
 gas/testsuite/gas/csky/pr28168.s        |  1 +
 gas/testsuite/gas/csky/v2_float_part2.d | 16 ++++++++--------
 opcodes/csky-dis.c                      |  8 ++++----
 4 files changed, 25 insertions(+), 12 deletions(-)
 create mode 100644 gas/testsuite/gas/csky/pr28168.d
 create mode 100644 gas/testsuite/gas/csky/pr28168.s

diff --git a/gas/testsuite/gas/csky/pr28168.d b/gas/testsuite/gas/csky/pr28168.d
new file mode 100644
index 00000000000..0e7d6dada0e
--- /dev/null
+++ b/gas/testsuite/gas/csky/pr28168.d
@@ -0,0 +1,12 @@
+#as: -mcpu=ck807f
+#objdump: -d
+
+
+.*: +file format .*csky.*
+
+Disassembly of section \.text:
+
+00000000 <\.text>:
+[ 	]+[0-9a-f]+:[ 	]+f4003910[ 	]+flrwd[ 	]+fr0, 8\.721012e\+150
+[ 	]+[0-9a-f]+:[ 	]+417f3259[ 	]+\.long[ 	]+0x417f3259
+[ 	]+[0-9a-f]+:[ 	]+5f45504f[ 	]+\.long[ 	]+0x5f45504f
diff --git a/gas/testsuite/gas/csky/pr28168.s b/gas/testsuite/gas/csky/pr28168.s
new file mode 100644
index 00000000000..323eed4eea3
--- /dev/null
+++ b/gas/testsuite/gas/csky/pr28168.s
@@ -0,0 +1 @@
+flrwd fr0, 8.721012e+150
diff --git a/gas/testsuite/gas/csky/v2_float_part2.d b/gas/testsuite/gas/csky/v2_float_part2.d
index 78fa37bc038..ecb6c156bdf 100644
--- a/gas/testsuite/gas/csky/v2_float_part2.d
+++ b/gas/testsuite/gas/csky/v2_float_part2.d
@@ -6,15 +6,15 @@
 
 Disassembly of section \.text:
 #...
-\s*[0-9a-f]*:\s*f4003882\s*flrws\s*fr2,\s*3\.140000
-\s*[0-9a-f]*:\s*f50b1c02\s*fmovis\s*fr2,\s*1\.500000
-\s*[0-9a-f]*:\s*f51b1c02\s*fmovis\s*fr2,\s*-1\.500000
-\s*[0-9a-f]*:\s*f48a1c02\s*fmovis\s*fr2,\s*2\.500000
+\s*[0-9a-f]*:\s*f4003882\s*flrws\s*fr2,\s*3\.14
+\s*[0-9a-f]*:\s*f50b1c02\s*fmovis\s*fr2,\s*1\.5
+\s*[0-9a-f]*:\s*f51b1c02\s*fmovis\s*fr2,\s*-1\.5
+\s*[0-9a-f]*:\s*f48a1c02\s*fmovis\s*fr2,\s*2\.5
 #...
-\s*[0-9a-f]*:\s*f4003952\s*flrwd\s*fr2,\s*3\.140000
-\s*[0-9a-f]*:\s*f48a1e02\s*fmovid\s*fr2,\s*2\.500000
-\s*[0-9a-f]*:\s*f49a1e02\s*fmovid\s*fr2,\s*-2\.500000
-\s*[0-9a-f]*:\s*f51b1e02\s*fmovid\s*fr2,\s*-1\.500000
+\s*[0-9a-f]*:\s*f4003952\s*flrwd\s*fr2,\s*3\.14
+\s*[0-9a-f]*:\s*f48a1e02\s*fmovid\s*fr2,\s*2\.5
+\s*[0-9a-f]*:\s*f49a1e02\s*fmovid\s*fr2,\s*-2\.5
+\s*[0-9a-f]*:\s*f51b1e02\s*fmovid\s*fr2,\s*-1\.5
 \s*[0-9a-f]*:\s*4048f5c3\s*\.long\s*0x4048f5c3
 \s*[0-9a-f]*:\s*51eb851f\s*\.long\s*0x51eb851f
 \s*[0-9a-f]*:\s*40091eb8\s*\.long\s*0x40091eb8
diff --git a/opcodes/csky-dis.c b/opcodes/csky-dis.c
index cdd911be09a..cca8d364901 100644
--- a/opcodes/csky-dis.c
+++ b/opcodes/csky-dis.c
@@ -565,7 +565,7 @@ csky_output_operand (char *str, struct operand const *oprnd,
 				      ? &floatformat_ieee_double_big
 				      : &floatformat_ieee_double_little),
 				     ibytes, &f);
-	    sprintf (buf, "%f", f);
+	    sprintf (buf, "%.7g", f);
 	  }
 	else
 	  {
@@ -645,7 +645,7 @@ csky_output_operand (char *str, struct operand const *oprnd,
 	floatformat_to_double (&floatformat_ieee_double_little, valbytes,
 			       &fvalue);
 
-	sprintf (buf, "%f", fvalue);
+	sprintf (buf, "%.7g", fvalue);
 	strcat (str, buf);
 	break;
       }
@@ -673,7 +673,7 @@ csky_output_operand (char *str, struct operand const *oprnd,
 
 	float f = 0;
 	memcpy (&f, &value, sizeof (float));
-	sprintf (buf, "%f\t// imm9:%4d, imm4:%2d", f, imm8, imm4);
+	sprintf (buf, "%.7g\t// imm9:%4d, imm4:%2d", f, imm8, imm4);
 	strcat (str, buf);
 
 	break;
@@ -702,7 +702,7 @@ csky_output_operand (char *str, struct operand const *oprnd,
 	  }
 	double d = 0;
 	memcpy (&d, &dvalue, sizeof (double));
-	sprintf (buf, "%lf\t// imm9:%4ld, imm4:%2ld", d, (long) imm8, (long) imm4);
+	sprintf (buf, "%.7g\t// imm9:%4ld, imm4:%2ld", d, (long) imm8, (long) imm4);
 	strcat (str, buf);
 
 	break;
-- 
2.17.1


             reply	other threads:[~2021-08-10  3:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-10  3:16 Lifang Xia [this message]
2021-08-11  5:07 ` Alan Modra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210810031657.428-1-lifang_xia@c-sky.com \
    --to=lifang_xia@c-sky.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).