< prev index next >

src/share/tools/hsdis/hsdis.c

Print this page
rev 8113 : 8076475: Misuses of strncpy/strncat
Summary: Various small fixes around strncpy and strncat
Reviewed-by: dsamersoff


 393       print_help(app_data, NULL, NULL);
 394     } else if (plen >= 5 && strncmp(p, "mach=", 5) == 0) {
 395       char*  mach_option = app_data->mach_option;
 396       size_t mach_size   = sizeof(app_data->mach_option);
 397       mach_size -= 1;           /*leave room for the null*/
 398       if (plen > mach_size)  plen = mach_size;
 399       strncpy(mach_option, p, plen);
 400       mach_option[plen] = '\0';
 401     } else if (plen > 6 && strncmp(p, "hsdis-", 6) == 0) {
 402       // do not pass these to the next level
 403     } else {
 404       /* just copy it; {i386,sparc}-dis.c might like to see it  */
 405       if (iop > iop_base && iop < iop_limit)  (*iop++) = ',';
 406       if (iop + plen > iop_limit)
 407         plen = iop_limit - iop;
 408       strncpy(iop, p, plen);
 409       iop += plen;
 410     }
 411     p = q;
 412   }

 413 }
 414 
 415 static void print_help(struct hsdis_app_data* app_data,
 416                        const char* msg, const char* arg) {
 417   DECL_PRINTF_CALLBACK(app_data);
 418   if (msg != NULL) {
 419     (*printf_callback)(printf_stream, "hsdis: ");
 420     (*printf_callback)(printf_stream, msg, arg);
 421     (*printf_callback)(printf_stream, "\n");
 422   }
 423   (*printf_callback)(printf_stream, "hsdis output options:\n");
 424   if (printf_callback == (printf_callback_t) &fprintf)
 425     disassembler_usage((FILE*) printf_stream);
 426   else
 427     disassembler_usage(stderr); /* better than nothing */
 428   (*printf_callback)(printf_stream, "  mach=<arch>   select disassembly mode\n");
 429 #if defined(LIBARCH_i386) || defined(LIBARCH_amd64)
 430   (*printf_callback)(printf_stream, "  mach=i386     select 32-bit mode\n");
 431   (*printf_callback)(printf_stream, "  mach=x86-64   select 64-bit mode\n");
 432   (*printf_callback)(printf_stream, "  suffix        always print instruction suffix\n");




 393       print_help(app_data, NULL, NULL);
 394     } else if (plen >= 5 && strncmp(p, "mach=", 5) == 0) {
 395       char*  mach_option = app_data->mach_option;
 396       size_t mach_size   = sizeof(app_data->mach_option);
 397       mach_size -= 1;           /*leave room for the null*/
 398       if (plen > mach_size)  plen = mach_size;
 399       strncpy(mach_option, p, plen);
 400       mach_option[plen] = '\0';
 401     } else if (plen > 6 && strncmp(p, "hsdis-", 6) == 0) {
 402       // do not pass these to the next level
 403     } else {
 404       /* just copy it; {i386,sparc}-dis.c might like to see it  */
 405       if (iop > iop_base && iop < iop_limit)  (*iop++) = ',';
 406       if (iop + plen > iop_limit)
 407         plen = iop_limit - iop;
 408       strncpy(iop, p, plen);
 409       iop += plen;
 410     }
 411     p = q;
 412   }
 413   *iop = '\0';
 414 }
 415 
 416 static void print_help(struct hsdis_app_data* app_data,
 417                        const char* msg, const char* arg) {
 418   DECL_PRINTF_CALLBACK(app_data);
 419   if (msg != NULL) {
 420     (*printf_callback)(printf_stream, "hsdis: ");
 421     (*printf_callback)(printf_stream, msg, arg);
 422     (*printf_callback)(printf_stream, "\n");
 423   }
 424   (*printf_callback)(printf_stream, "hsdis output options:\n");
 425   if (printf_callback == (printf_callback_t) &fprintf)
 426     disassembler_usage((FILE*) printf_stream);
 427   else
 428     disassembler_usage(stderr); /* better than nothing */
 429   (*printf_callback)(printf_stream, "  mach=<arch>   select disassembly mode\n");
 430 #if defined(LIBARCH_i386) || defined(LIBARCH_amd64)
 431   (*printf_callback)(printf_stream, "  mach=i386     select 32-bit mode\n");
 432   (*printf_callback)(printf_stream, "  mach=x86-64   select 64-bit mode\n");
 433   (*printf_callback)(printf_stream, "  suffix        always print instruction suffix\n");


< prev index next >