11/*
2- * Copyright (c) 2008, 2021 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2008, 2023 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * The Universal Permissive License (UPL), Version 1.0
@@ -219,6 +219,8 @@ static void* decode(struct hsdis_app_data* app_data, const char* options) {
219219const decode_func_vtype decode_func_virtual_address = & decode_instructions_virtual ;
220220const decode_func_stype decode_func_address = & decode_instructions ;
221221
222+ #define remaining_buflen (buf , bufsize , p ) ((bufsize) - ((p) - (buf)))
223+
222224static const char * format_insn_close (const char * close ,
223225 disassemble_info * dinfo ,
224226 char * buf , size_t bufsize ) {
@@ -244,9 +246,9 @@ static const char* format_insn_close(const char* close,
244246
245247 strcpy (buf , close );
246248 char * p = buf ;
247- if (type ) sprintf (p += strlen (p ), " type='%s'" , type );
248- if (dsize ) sprintf (p += strlen (p ), " dsize='%d'" , dsize );
249- if (delays ) sprintf (p += strlen (p ), " delay='%d'" , delays );
249+ if (type ) snprintf (p += strlen (p ), remaining_buflen ( buf , bufsize , p ), " type='%s'" , type );
250+ if (dsize ) snprintf (p += strlen (p ), remaining_buflen ( buf , bufsize , p ), " dsize='%d'" , dsize );
251+ if (delays ) snprintf (p += strlen (p ), remaining_buflen ( buf , bufsize , p ), " delay='%d'" , delays );
250252 return buf ;
251253}
252254
0 commit comments