From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70044.outbound.protection.outlook.com [40.107.7.44]) by sourceware.org (Postfix) with ESMTPS id CB91F3858D33 for ; Fri, 10 Jun 2022 13:36:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CB91F3858D33 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uq/F1ZuD0NCxVoFjRVABpwZDnzhjy4bHqjK2t5Mm/ScBID3fLnO9O9zms1QL/kijhBXm8l4Z8YEZgUmUreUfuH14nf/3nqXs6v3XLo0WSGGePsLDpnn2cQedPqV/5oTwC0gZXsF71EXqLGiNJ9svFU6S8v794PUIDRXNm0AiIYI2t8P2zstwmX1cP6IGoasnhQejyoFImRR2B8uoEkrIi+p9FBG4SZ2V6i4aSIvjLy4Y9DyHd+xT7NJFxmi7vNDIwuUETHmPzYUhgdwkkhLGv0qDUA1DbjBhELWZMXZaQBvpfbezvGtZdp0cuy57bxMdBzVrYliwhCE6smgE9X1WVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Yjy4MontU70EDG57DyC6PhwzREooO0jrkO8OpWZDnTs=; b=KSAYAQjhvfTLCM1Y+yrc5HVEBmiT71/kXH9SQY/zyInVeQ/wVgK9Pq29EPKdaJTp9pcqUpkUOz2mo92iTKCLI7OBSEm5qlhYpbJHuY0Uxfx2QTBDjAzMMQlMvulTbkl8fbdMKWF9SxegCz+yW4TYttzSgznGh7OHk9gLyf3ehSJKoswpCLcu3TUskFLduukKtYxGqlHynVHaOf8sGPcqT5HBbFc2VQJyMcN6v30jrygN2GdVOUTOUrbAeVw3CaGnhgEe9XpkbcbYmzPPNvFMIU+SVGGXFWIRNniZFBbelURv5H4lDCX/abxcEKq8R18w1wdYnZ2hv5TklqVA63zoUg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Received: from VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) by PAXPR04MB8095.eurprd04.prod.outlook.com (2603:10a6:102:1c6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.14; Fri, 10 Jun 2022 13:36:32 +0000 Received: from VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::dfa:a64a:432f:e26b]) by VE1PR04MB6560.eurprd04.prod.outlook.com ([fe80::dfa:a64a:432f:e26b%7]) with mapi id 15.20.5332.013; Fri, 10 Jun 2022 13:36:31 +0000 Message-ID: Date: Fri, 10 Jun 2022 15:36:30 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: [PATCH 4/4] x86: replace global scratch buffer Content-Language: en-US To: Binutils References: <6fd28ca0-2af4-7335-18d3-31036dea7a4f@suse.com> Cc: "H.J. Lu" , Andrew Burgess From: Jan Beulich In-Reply-To: <6fd28ca0-2af4-7335-18d3-31036dea7a4f@suse.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AS9PR05CA0026.eurprd05.prod.outlook.com (2603:10a6:20b:488::31) To VE1PR04MB6560.eurprd04.prod.outlook.com (2603:10a6:803:122::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 36871b06-d135-447a-b5ba-08da4ae63ad9 X-MS-TrafficTypeDiagnostic: PAXPR04MB8095:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: B0uTEkyZql0SSaKbafOdtAqbs61J7IDp4BwMkP630qrLqLgb43y5IP9PcSuL4af99Tof/o++Mnwl8enMpY+pbodj5CNz0B2xY5yTv6C5/lzmk0kpSZKWYdWsGAOjY4r/NnEZGu+4PFIjXPmoFsucDgNfv8MC3u3sfv2ukH0OP+XmAS7tktgvWtAwnVzQK1Zc3mC0z6lGwX09X5ZTE+m5hKVfhAxBrLIkmUHMI/t8sRXROWhJjcqpKne0k/ss7UtBevQfqfyJ4z+yL9wdF5BFxX0kq/Dvvw9yaZeItnhpchz5svSvEUftLcbsAEcLDCUEbH7fP7GKvmRyW3xc8zYz8qGxxd77+LK6KQXoYRqnh426S2Rd7/F202jTHkGnlIdftGScKcXux7jn+0yGgsiXhBV8Rsn4iFDnowpCwiT+Wi3qBT2RfYKBZN6E99zEcXgoI3po4Jif5W4Li+a+pITIerhLrefbfelxld489RveY7RYBcIqdlRkbycimUjioJ7ZMNtV2aY/2mR8izzIef9NPiPApSW/oZKlgcjpeV9yk5/v78c3PdVsYqA2mORzGEulbm918aieadu2QYFQF64vqTh0xxhPVggW7Ph1UxDsWThshnX++zyAAMrF1ajQJE/0Jj+xJu7ONFh22V80p4raPyMKBfOMxf7lhoAWqllnU5cf5bvi/aoZAp5El1jYuFJk0+YKZC0txpt/iWotmQQZD8oIIIjOal7Xci2M8q5cuYVCAdm3MdqOcufpfXZL8ftn X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VE1PR04MB6560.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(66476007)(86362001)(31696002)(38100700002)(54906003)(31686004)(66556008)(2906002)(6916009)(508600001)(6486002)(30864003)(8936002)(5660300002)(66946007)(83380400001)(26005)(36756003)(2616005)(316002)(6512007)(186003)(8676002)(4326008)(6506007)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?MWdoZ3F1MGNNMGtQZTBUcGY3a3JrS0RSdm1aVmtDaUIyYVhTeXFvbDJ5YzhH?= =?utf-8?B?cHE0L05udy9XOWpPUmViNXZpMGFkUDJSa1ptQWtoYkNVZDFodFRaVnB5Mi9N?= =?utf-8?B?cW1ld0NNWnRsazVTcW85MEVWWkdJblkzT0Jtam9YNVV4RjlxcXJnSlp2TXI3?= =?utf-8?B?eElIUFNlalg4Z3VmajlOamJ3bU5qbitGYUhZSlBzdTNWZUpUVitkd1pRRFRI?= =?utf-8?B?QzhKb1JUSld4dElaYzU4TFhxckN4U2hXUTA1WHVlbG55a05LSmN1azB4Yy9k?= =?utf-8?B?VzFuNC9wSXB5azY2TWMwMWF1SzB1Szl4T25YRGgreWIwWFc0MHRDTEdEUDJC?= =?utf-8?B?OTdxY3lZeGNiQkVKR09GYjdSUTZQWXFPTmhSYUd1MHpOelVMa3ZsR05xclpy?= =?utf-8?B?eEhIMVplYUJyWGVCTVVueUJscWZlVWlweHhhL2o5T3NqamhuL0F2cnRDTTNl?= =?utf-8?B?MllHZlNPdjZYT0w2a1JJTC81dENtUFYrRjNmc0RVbGxscG9jd2p4YjR5T2lQ?= =?utf-8?B?RDBjaHQva0hxb0NzWit1V3FucGhvd0tITUpoYXRSc2dFcFAyNklldGZyWXIw?= =?utf-8?B?SzgxZS9VS2dBVlFOa0c4OTRkMGFhZFVXYXRZNzV4TmNHV3d4SzJJNHBNR2dk?= =?utf-8?B?QnFEM2FyRlorUUhsQ0VTdUYrUWhTeGZNcTVBZUtpbTVuWmo0YWNodWI3OHRa?= =?utf-8?B?eFh5TVJRcTRBcFBrOXJCMmJ6UXJReFNHZzczQkNzelVkR3RpakNTRjdzRHNI?= =?utf-8?B?Yi8vNnNyUi83ZWlBMFcxS1RoVU54N0M3Wjd0dzZydkkveDgxcDNFeklLMWlU?= =?utf-8?B?UEJYdThPdHBXNzMxZmZZbTk0WkF2MUlZNUYrajlQOGE2aGt5Q1B4cjZEd3F3?= =?utf-8?B?ZG8rSVdWNGFOcTNucDVFaTQ2bzRVeXdqM25uT0R3dmdnVlh6ZDdocGs1MlBr?= =?utf-8?B?bmdDVStLRnI1bkF1MkVTL2llTHhuOS9vcDk4ZGpGMXhXTGRNUTY2dk5nUWNo?= =?utf-8?B?UlhIUk9BVURveVNPT2JHUTR3MmZVK3hKWnVKdVdVOUlzdU9LdzJVUVl4Qmcr?= =?utf-8?B?cUovUmtJK0tjUy9SY1RrS2pPU0hla2xidVZZanFqNEQ5cnNyeWQrQ1ovMWR1?= =?utf-8?B?UmFudzREcWFTVUM0UFQ2N0lWQ3hxMEFlZlpPTmQxOVdxY1U2QkJ0SFRPdkxl?= =?utf-8?B?TkVicGNGbzJ3THBucU9JUmVHMDh4anNOSnoyWkc3RGtwQnVObUp2OUU2cDBB?= =?utf-8?B?S0NlWFdWaTZaV1hQTU1iWVRMNGVjdVJYYzUxMFF2Wlo0V05tZitpcXRiMDAw?= =?utf-8?B?ZFJveDhlNERWUzBlNWNyZ0E0UnczM0tYa2hadFNqeVNZYnE5azZVR0FQeWFH?= =?utf-8?B?TnlCNUJTS0hFSDRjZjIvb2FrVmcxNWRMSlVlSUNvb1M5L21MeGFla0tJemZy?= =?utf-8?B?RVkrUzQxUFFDdHQ2ekdxOEJVSy8vWTh2OGxUaUFKYVF6dWNGVVNUTXhSZDJk?= =?utf-8?B?L05YSUgvV0FMVHE1VVJPRXg4ak9GV3d4MVI5WjhtYTFLdDA4RllFb2QzVVFZ?= =?utf-8?B?YThZYkZTMmo1SGovYnZwWFJMT1FwMnFacGVHQnlBOXVvOEUxWmtWcFowMmRO?= =?utf-8?B?VmVUNG1TQytkNzNUWTJPNEJXNUJSL3hyMVB2Y3hVWGpac0hHNUcrNzcrNHJa?= =?utf-8?B?RldZZUYxeGRjT3ZOc1kzRmx1cHltd3ZPNzlneFg5ckNrdmxXeUJCRUhWMURx?= =?utf-8?B?N1NOM2R3U3VkaS9VN1NuWVB2SmtlbmpSVmJoZG42QmxFNHhyaFZuT293Wmw3?= =?utf-8?B?YUVQQXQyVXp5blVncVhidTUzUXUzT3IzS2dsN2s3a3JFczYvUTJXcWduRzZL?= =?utf-8?B?dXp6QVZTa0psSTJrN3A4WEUxSDFJTS9lcmlpUmR5Vm1xaG9CNWtGUklYeUVW?= =?utf-8?B?WUxZZjRQYXVPQmFlR3k4MlNWallFVnVkME5jWjdkNThYYWc1Yml5U0tXMGdi?= =?utf-8?B?MUVIc0JhREZ1cmJGZVVhK0hNK3hFZGc0L3NYeTlCcXIwb3dsOGR6ekE4cXpX?= =?utf-8?B?U1hlK3R6NVJCa2ZqanM0cE1aMGllckpxRzJSNnVTdGlIVnhhV0RiVTdCeXpx?= =?utf-8?B?ZVFTWjluZGsvSU4xRVVZK3BQME1idGRjWG80ZXJkRW5Gdm9DeENOTWt4SmRE?= =?utf-8?B?VDB3QVI0UzdSRXBsdnp4R2h1cHlIODNid2RyTWYwV2V0YTNPUjVNeEpjRmFZ?= =?utf-8?B?dmhDMjlySGt0N1FqbzYrU1dJbWlXNjRzQ1d5MU40Wndod3FsM3JaZnFkbnBC?= =?utf-8?B?RnRRVG0wSEpZN3dDZzdXcmNld3IybjJPd1hVRys0cGhBcm8zOHpGZz09?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36871b06-d135-447a-b5ba-08da4ae63ad9 X-MS-Exchange-CrossTenant-AuthSource: VE1PR04MB6560.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2022 13:36:31.8657 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LyzPBuNSPJq/gm2wt36N8vYDWWyi5CW4hatt4yU+RNCfTlG6SpivmUUdcrYlbXbU+RcRgOE/3qKcX8NK0jR3+A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8095 X-Spam-Status: No, score=-3031.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Jun 2022 13:36:38 -0000 With its movement to the stack, and with the subsequent desire to initialize the entire instr_info instances, this has become doubly inefficient. Individual users have better knowledge of how big a buffer they need, and in a number of cases going through an intermediate buffer can be avoided altogether. Having got confirmation that it wasn't intentional to print memory operand displacements with inconsistent style, print_displacement() is now using dis_style_address_offset consistently (eliminating the need for callers to pass in a style). While touching print_operand_value() also convert its "hex" parameter to bool. And while altering (and moving) oappend_immediate(), fold oappend_maybe_intel_with_style() into its only remaining caller. Finally where doing adjustments, use snprintf() in favor of sprintf(). --- While doing the conversion I came to notice that print_operand_value()'s "hex" parameter has only ever passed "true" to it. I wonder why this parameter still exists. --- a/opcodes/i386-dis.c +++ b/opcodes/i386-dis.c @@ -51,9 +51,7 @@ static void oappend_with_style (instr_in static void oappend (instr_info *, const char *); static void append_seg (instr_info *); static void OP_indirE (instr_info *, int, int); -static void print_operand_value (instr_info *, char *, int, bfd_vma); static void OP_E_memory (instr_info *, int, int); -static void print_displacement (instr_info *, char *, bfd_vma); static void OP_E (instr_info *, int, int); static void OP_G (instr_info *, int, int); static bfd_vma get64 (instr_info *); @@ -170,7 +168,6 @@ struct instr_info char obuf[100]; char *obufp; char *mnemonicendp; - char scratchbuf[100]; unsigned char *start_codep; unsigned char *insn_codep; unsigned char *codep; @@ -9254,37 +9251,13 @@ get_sib (instr_info *ins, int sizeflag) ins->has_sib = false; } -/* Like oappend (below), but S is a string starting with '%' or '$'. In - Intel syntax, the '%' or '$' is elided. STYLE is used when displaying - this part of the output in the disassembler. - - This function should not be used directly from the general disassembler - code, instead the helpers oappend_register and oappend_immediate should - be called as appropriate. */ - -static void -oappend_maybe_intel_with_style (instr_info *ins, const char *s, - enum disassembler_style style) -{ - oappend_with_style (ins, s + ins->intel_syntax, style); -} - -/* Like oappend_maybe_intel_with_style above, but called when S is the - name of a register. */ +/* Like oappend (below), but S is a string starting with '%'. In + Intel syntax, the '%' is elided. */ static void oappend_register (instr_info *ins, const char *s) { - oappend_maybe_intel_with_style (ins, s, dis_style_register); -} - -/* Like oappend_maybe_intel_with_style above, but called when S represents - an immediate. */ - -static void -oappend_immediate (instr_info *ins, const char *s) -{ - oappend_maybe_intel_with_style (ins, s, dis_style_immediate); + oappend_with_style (ins, s + ins->intel_syntax, dis_style_register); } /* Wrap around a call to INS->info->fprintf_styled_func, printing FMT. @@ -10334,8 +10307,12 @@ static void OP_STi (instr_info *ins, int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED) { - sprintf (ins->scratchbuf, "%%st(%d)", ins->modrm.rm); - oappend_register (ins, ins->scratchbuf); + char scratch[8]; + int res = snprintf (scratch, ARRAY_SIZE (scratch), "%%st(%d)", ins->modrm.rm); + + if (res < 0 || (size_t) res >= ARRAY_SIZE (scratch)) + abort (); + oappend_register (ins, scratch); } /* Capital letters in template are macros. */ @@ -10992,39 +10969,39 @@ OP_indirE (instr_info *ins, int bytemode } static void -print_operand_value (instr_info *ins, char *buf, int hex, bfd_vma disp) +print_operand_value (instr_info *ins, bool hex, bfd_vma disp, + enum disassembler_style style) { + char tmp[30]; + if (ins->address_mode == mode_64bit) { if (hex) { - char tmp[30]; int i; - buf[0] = '0'; - buf[1] = 'x'; + oappend_with_style (ins, "0x", style); sprintf_vma (tmp, disp); for (i = 0; tmp[i] == '0' && tmp[i + 1]; i++); - strcpy (buf + 2, tmp + i); + oappend_with_style (ins, tmp + i, style); } else { bfd_signed_vma v = disp; - char tmp[30]; int i; if (v < 0) { - *(buf++) = '-'; + oappend_char_with_style (ins, '-', style); v = -disp; /* Check for possible overflow on 0x8000000000000000. */ if (v < 0) { - strcpy (buf, "9223372036854775808"); + oappend_with_style (ins, "9223372036854775808", style); return; } } if (!v) { - strcpy (buf, "0"); + oappend_char_with_style (ins, '0', style); return; } @@ -11036,30 +11013,41 @@ print_operand_value (instr_info *ins, ch v /= 10; i++; } - strcpy (buf, tmp + 29 - i); + oappend_with_style (ins, tmp + 29 - i, style); } } else { if (hex) - sprintf (buf, "0x%x", (unsigned int) disp); + sprintf (tmp, "0x%x", (unsigned int) disp); else - sprintf (buf, "%d", (int) disp); + sprintf (tmp, "%d", (int) disp); + oappend_with_style (ins, tmp, style); } } +/* Like oappend, but called for immediate operands. */ + +static void +oappend_immediate (instr_info *ins, bfd_vma imm) +{ + if (!ins->intel_syntax) + oappend_char_with_style (ins, '$', dis_style_immediate); + print_operand_value (ins, true, imm, dis_style_immediate); +} + /* Put DISP in BUF as signed hex number. */ static void -print_displacement (instr_info *ins, char *buf, bfd_vma disp) +print_displacement (instr_info *ins, bfd_vma disp) { bfd_signed_vma val = disp; char tmp[30]; - int i, j = 0; + unsigned int i; if (val < 0) { - buf[j++] = '-'; + oappend_char_with_style (ins, '-', dis_style_address_offset); val = -disp; /* Check for possible overflow. */ @@ -11068,28 +11056,30 @@ print_displacement (instr_info *ins, cha switch (ins->address_mode) { case mode_64bit: - strcpy (buf + j, "0x8000000000000000"); + oappend_with_style (ins, "0x8000000000000000", + dis_style_address_offset); break; case mode_32bit: - strcpy (buf + j, "0x80000000"); + oappend_with_style (ins, "0x80000000", + dis_style_address_offset); break; case mode_16bit: - strcpy (buf + j, "0x8000"); + oappend_with_style (ins, "0x8000", + dis_style_address_offset); break; } return; } } - buf[j++] = '0'; - buf[j++] = 'x'; + oappend_with_style (ins, "0x", dis_style_address_offset); sprintf_vma (tmp, (bfd_vma) val); for (i = 0; tmp[i] == '0'; i++) continue; if (tmp[i] == '\0') i--; - strcpy (buf + j, tmp + i); + oappend_with_style (ins, tmp + i, dis_style_address_offset); } static void @@ -11729,11 +11719,9 @@ OP_E_memory (instr_info *ins, int bytemo if (ins->modrm.mod != 0 || base == 5) { if (havedisp || riprel) - print_displacement (ins, ins->scratchbuf, disp); + print_displacement (ins, disp); else - print_operand_value (ins, ins->scratchbuf, 1, disp); - oappend_with_style (ins, ins->scratchbuf, - dis_style_address_offset); + print_operand_value (ins, true, disp, dis_style_address_offset); if (riprel) { set_op (ins, disp, true); @@ -11792,9 +11780,8 @@ OP_E_memory (instr_info *ins, int bytemo : att_index32); oappend_char (ins, ins->scale_char); - sprintf (ins->scratchbuf, "%d", 1 << scale); - oappend_with_style (ins, ins->scratchbuf, - dis_style_immediate); + oappend_char_with_style (ins, '0' + (1 << scale), + dis_style_immediate); } } if (ins->intel_syntax @@ -11809,10 +11796,9 @@ OP_E_memory (instr_info *ins, int bytemo } if (havedisp) - print_displacement (ins, ins->scratchbuf, disp); + print_displacement (ins, disp); else - print_operand_value (ins, ins->scratchbuf, 1, disp); - oappend (ins, ins->scratchbuf); + print_operand_value (ins, true, disp, dis_style_address_offset); } oappend_char (ins, ins->close_char); @@ -11839,8 +11825,7 @@ OP_E_memory (instr_info *ins, int bytemo oappend_register (ins, att_names_seg[ds_reg - es_reg]); oappend (ins, ":"); } - print_operand_value (ins, ins->scratchbuf, 1, disp); - oappend (ins, ins->scratchbuf); + print_operand_value (ins, true, disp, dis_style_text); } } } @@ -11885,10 +11870,7 @@ OP_E_memory (instr_info *ins, int bytemo if (!ins->intel_syntax) if (ins->modrm.mod != 0 || ins->modrm.rm == 6) - { - print_displacement (ins, ins->scratchbuf, disp); - oappend (ins, ins->scratchbuf); - } + print_displacement (ins, disp); if (ins->modrm.mod != 0 || ins->modrm.rm != 6) { @@ -11906,8 +11888,7 @@ OP_E_memory (instr_info *ins, int bytemo disp = -disp; } - print_displacement (ins, ins->scratchbuf, disp); - oappend (ins, ins->scratchbuf); + print_displacement (ins, disp); } oappend_char (ins, ins->close_char); @@ -11919,8 +11900,7 @@ OP_E_memory (instr_info *ins, int bytemo oappend_register (ins, att_names_seg[ds_reg - es_reg]); oappend (ins, ":"); } - print_operand_value (ins, ins->scratchbuf, 1, disp & 0xffff); - oappend (ins, ins->scratchbuf); + print_operand_value (ins, true, disp & 0xffff, dis_style_text); } } if (ins->vex.b) @@ -12274,10 +12254,7 @@ OP_I (instr_info *ins, int bytemode, int } op &= mask; - ins->scratchbuf[0] = '$'; - print_operand_value (ins, ins->scratchbuf + 1, 1, op); - oappend_immediate (ins, ins->scratchbuf); - ins->scratchbuf[0] = '\0'; + oappend_immediate (ins, op); } static void @@ -12292,10 +12269,7 @@ OP_I64 (instr_info *ins, int bytemode, i USED_REX (REX_W); - ins->scratchbuf[0] = '$'; - print_operand_value (ins, ins->scratchbuf + 1, 1, get64 (ins)); - oappend_immediate (ins, ins->scratchbuf); - ins->scratchbuf[0] = '\0'; + oappend_immediate (ins, get64 (ins)); } static void @@ -12346,9 +12320,7 @@ OP_sI (instr_info *ins, int bytemode, in return; } - ins->scratchbuf[0] = '$'; - print_operand_value (ins, ins->scratchbuf + 1, 1, op); - oappend_immediate (ins, ins->scratchbuf); + oappend_immediate (ins, op); } static void @@ -12398,8 +12370,7 @@ OP_J (instr_info *ins, int bytemode, int disp = ((ins->start_pc + (ins->codep - ins->start_codep) + disp) & mask) | segment; set_op (ins, disp, false); - print_operand_value (ins, ins->scratchbuf, 1, disp); - oappend (ins, ins->scratchbuf); + print_operand_value (ins, true, disp, dis_style_text); } static void @@ -12414,7 +12385,8 @@ OP_SEG (instr_info *ins, int bytemode, i static void OP_DIR (instr_info *ins, int dummy ATTRIBUTE_UNUSED, int sizeflag) { - int seg, offset; + int seg, offset, res; + char scratch[24]; if (sizeflag & DFLAG) { @@ -12427,11 +12399,13 @@ OP_DIR (instr_info *ins, int dummy ATTRI seg = get16 (ins); } ins->used_prefixes |= (ins->prefixes & PREFIX_DATA); - if (ins->intel_syntax) - sprintf (ins->scratchbuf, "0x%x:0x%x", seg, offset); - else - sprintf (ins->scratchbuf, "$0x%x,$0x%x", seg, offset); - oappend (ins, ins->scratchbuf); + + res = snprintf (scratch, ARRAY_SIZE (scratch), + ins->intel_syntax ? "0x%x:0x%x" : "$0x%x,$0x%x", + seg, offset); + if (res < 0 || (size_t) res >= ARRAY_SIZE (scratch)) + abort (); + oappend (ins, scratch); } static void @@ -12456,8 +12430,7 @@ OP_OFF (instr_info *ins, int bytemode, i oappend (ins, ":"); } } - print_operand_value (ins, ins->scratchbuf, 1, off); - oappend_with_style (ins, ins->scratchbuf, dis_style_address_offset); + print_operand_value (ins, true, off, dis_style_address_offset); } static void @@ -12486,8 +12459,7 @@ OP_OFF64 (instr_info *ins, int bytemode, oappend (ins, ":"); } } - print_operand_value (ins, ins->scratchbuf, 1, off); - oappend_with_style (ins, ins->scratchbuf, dis_style_address_offset); + print_operand_value (ins, true, off, dis_style_address_offset); } static void @@ -12568,7 +12540,9 @@ static void OP_C (instr_info *ins, int dummy ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED) { - int add; + int add, res; + char scratch[8]; + if (ins->rex & REX_R) { USED_REX (REX_R); @@ -12582,33 +12556,44 @@ OP_C (instr_info *ins, int dummy ATTRIBU } else add = 0; - sprintf (ins->scratchbuf, "%%cr%d", ins->modrm.reg + add); - oappend_register (ins, ins->scratchbuf); + res = snprintf (scratch, ARRAY_SIZE (scratch), "%%cr%d", + ins->modrm.reg + add); + if (res < 0 || (size_t) res >= ARRAY_SIZE (scratch)) + abort (); + oappend_register (ins, scratch); } static void OP_D (instr_info *ins, int dummy ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED) { - int add; + int add, res; + char scratch[8]; + USED_REX (REX_R); if (ins->rex & REX_R) add = 8; else add = 0; - if (ins->intel_syntax) - sprintf (ins->scratchbuf, "dr%d", ins->modrm.reg + add); - else - sprintf (ins->scratchbuf, "%%db%d", ins->modrm.reg + add); - oappend (ins, ins->scratchbuf); + res = snprintf (scratch, ARRAY_SIZE (scratch), + ins->intel_syntax ? "dr%d" : "%%db%d", + ins->modrm.reg + add); + if (res < 0 || (size_t) res >= ARRAY_SIZE (scratch)) + abort (); + oappend (ins, scratch); } static void OP_T (instr_info *ins, int dummy ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED) { - sprintf (ins->scratchbuf, "%%tr%d", ins->modrm.reg); - oappend_register (ins, ins->scratchbuf); + int res; + char scratch[8]; + + res = snprintf (scratch, ARRAY_SIZE (scratch), "%%tr%d", ins->modrm.reg); + if (res < 0 || (size_t) res >= ARRAY_SIZE (scratch)) + abort (); + oappend_register (ins, scratch); } static void @@ -13060,10 +13045,7 @@ CMP_Fixup (instr_info *ins, int bytemode else { /* We have a reserved extension byte. Output it directly. */ - ins->scratchbuf[0] = '$'; - print_operand_value (ins, ins->scratchbuf + 1, 1, cmp_type); - oappend_immediate (ins, ins->scratchbuf); - ins->scratchbuf[0] = '\0'; + oappend_immediate (ins, cmp_type); } } @@ -13515,9 +13497,7 @@ static void OP_VexI4 (instr_info *ins, int bytemode ATTRIBUTE_UNUSED, int sizeflag ATTRIBUTE_UNUSED) { - ins->scratchbuf[0] = '$'; - print_operand_value (ins, ins->scratchbuf + 1, 1, ins->codep[-1] & 0xf); - oappend_immediate (ins, ins->scratchbuf); + oappend_immediate (ins, ins->codep[-1] & 0xf); } static void @@ -13560,10 +13540,7 @@ VPCMP_Fixup (instr_info *ins, int bytemo else { /* We have a reserved extension byte. Output it directly. */ - ins->scratchbuf[0] = '$'; - print_operand_value (ins, ins->scratchbuf + 1, 1, cmp_type); - oappend_immediate (ins, ins->scratchbuf); - ins->scratchbuf[0] = '\0'; + oappend_immediate (ins, cmp_type); } } @@ -13612,10 +13589,7 @@ VPCOM_Fixup (instr_info *ins, int bytemo else { /* We have a reserved extension byte. Output it directly. */ - ins->scratchbuf[0] = '$'; - print_operand_value (ins, ins->scratchbuf + 1, 1, cmp_type); - oappend_immediate (ins, ins->scratchbuf); - ins->scratchbuf[0] = '\0'; + oappend_immediate (ins, cmp_type); } } @@ -13660,10 +13634,7 @@ PCLMUL_Fixup (instr_info *ins, int bytem else { /* We have a reserved extension byte. Output it directly. */ - ins->scratchbuf[0] = '$'; - print_operand_value (ins, ins->scratchbuf + 1, 1, pclmul_type); - oappend_immediate (ins, ins->scratchbuf); - ins->scratchbuf[0] = '\0'; + oappend_immediate (ins, pclmul_type); } }