From d2cdcfacaf77bbac0c9cf8b65c0088948c1303a3 Mon Sep 17 00:00:00 2001 From: Stanislav Shwartsman Date: Sun, 3 May 2009 19:21:38 +0000 Subject: [PATCH] added const to strings --- bochs/bx_debug/dbg_main.cc | 4 +- bochs/bx_debug/debug.h | 16 +++--- bochs/bx_debug/symbols.cc | 34 +++++------ bochs/config.cc | 8 +-- bochs/osdep.cc | 114 ++++++++++++++++++------------------- 5 files changed, 85 insertions(+), 91 deletions(-) diff --git a/bochs/bx_debug/dbg_main.cc b/bochs/bx_debug/dbg_main.cc index d7fe5814b..5706def2f 100644 --- a/bochs/bx_debug/dbg_main.cc +++ b/bochs/bx_debug/dbg_main.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: dbg_main.cc,v 1.192 2009-04-30 18:58:44 sshwarts Exp $ +// $Id: dbg_main.cc,v 1.193 2009-05-03 19:21:38 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -2671,7 +2671,7 @@ void bx_dbg_disassemble_command(const char *format, Bit64u from, Bit64u to) unsigned ilen = bx_disassemble.disasm(dis_size==32, dis_size==64, (bx_address)(-1), (bx_address)(-1), bx_disasm_ibuf, bx_disasm_tbuf); - char *Sym=bx_dbg_disasm_symbolic_address((Bit32u)from, 0); + const char *Sym=bx_dbg_disasm_symbolic_address((Bit32u)from, 0); dbg_printf("%08x: ", (unsigned) from); dbg_printf("(%20s): ", Sym?Sym:""); diff --git a/bochs/bx_debug/debug.h b/bochs/bx_debug/debug.h index 8d37e44a6..affc024b4 100644 --- a/bochs/bx_debug/debug.h +++ b/bochs/bx_debug/debug.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: debug.h,v 1.52 2009-04-07 16:12:19 sshwarts Exp $ +// $Id: debug.h,v 1.53 2009-05-03 19:21:38 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -313,13 +313,13 @@ void bx_dbg_show_param_command(char *param); int bx_dbg_show_symbolic(void); void bx_dbg_set_symbol_command(char *symbol, Bit32u val); -char* bx_dbg_symbolic_address(Bit32u context, Bit32u eip, Bit32u base); -char* bx_dbg_symbolic_address_16bit(Bit32u eip, Bit32u cs); -int bx_dbg_symbol_command(char* filename, bx_bool global, Bit32u offset); -void bx_dbg_info_symbols_command(char *Symbol); -int bx_dbg_lbreakpoint_symbol_command(char *Symbol); -Bit32u bx_dbg_get_symbol_value(char *Symbol); -char* bx_dbg_disasm_symbolic_address(Bit32u eip, Bit32u base); +const char* bx_dbg_symbolic_address(Bit32u context, Bit32u eip, Bit32u base); +const char* bx_dbg_symbolic_address_16bit(Bit32u eip, Bit32u cs); +int bx_dbg_symbol_command(const char* filename, bx_bool global, Bit32u offset); +void bx_dbg_info_symbols_command(const char *Symbol); +int bx_dbg_lbreakpoint_symbol_command(const char *Symbol); +Bit32u bx_dbg_get_symbol_value(const char *Symbol); +const char* bx_dbg_disasm_symbolic_address(Bit32u eip, Bit32u base); #ifdef __cplusplus } diff --git a/bochs/bx_debug/symbols.cc b/bochs/bx_debug/symbols.cc index 619d7ef34..c50823c02 100755 --- a/bochs/bx_debug/symbols.cc +++ b/bochs/bx_debug/symbols.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: symbols.cc,v 1.16 2009-05-03 18:31:23 sshwarts Exp $ +// $Id: symbols.cc,v 1.17 2009-05-03 19:21:38 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -33,7 +33,7 @@ static const char BX_HAVE_MAP_ERR[] = "context not implemented because BX_HAVE_MAP=0\n"; -char* bx_dbg_symbolic_address(Bit32u context, Bit32u eip, Bit32u base) +const char* bx_dbg_symbolic_address(Bit32u context, Bit32u eip, Bit32u base) { static bx_bool first = true; if (first) { @@ -43,35 +43,35 @@ char* bx_dbg_symbolic_address(Bit32u context, Bit32u eip, Bit32u base) return "unk. ctxt"; } -char* bx_dbg_symbolic_address_16bit(Bit32u eip, Bit32u cs) +const char* bx_dbg_symbolic_address_16bit(Bit32u eip, Bit32u cs) { // just prints an error anyway return bx_dbg_symbolic_address (0,0,0); } -int bx_dbg_symbol_command(char* filename, bx_bool global, Bit32u offset) +int bx_dbg_symbol_command(const char* filename, bx_bool global, Bit32u offset) { dbg_printf(BX_HAVE_MAP_ERR); return -1; } -void bx_dbg_info_symbols_command(char *Symbol) +void bx_dbg_info_symbols_command(const char *Symbol) { dbg_printf(BX_HAVE_MAP_ERR); } -int bx_dbg_lbreakpoint_symbol_command(char *Symbol) +int bx_dbg_lbreakpoint_symbol_command(const char *Symbol) { dbg_printf(BX_HAVE_MAP_ERR); return -1; } -Bit32u bx_dbg_get_symbol_value(char *Symbol) +Bit32u bx_dbg_get_symbol_value(const char *Symbol) { return 0; } -char* bx_dbg_disasm_symbolic_address(Bit32u eip, Bit32u base) +const char* bx_dbg_disasm_symbolic_address(Bit32u eip, Bit32u base) { return 0; } @@ -226,7 +226,7 @@ void symbol_entry_t::trim_quotes(void) } } -Bit32u bx_dbg_get_symbol_value(char *Symbol) +Bit32u bx_dbg_get_symbol_value(const char *Symbol) { context_t* cntx = context_t::get_context(0); if(!cntx) // Context not found @@ -242,7 +242,7 @@ Bit32u bx_dbg_get_symbol_value(char *Symbol) return sym->start; } -char* bx_dbg_symbolic_address(Bit32u context, Bit32u eip, Bit32u base) +const char* bx_dbg_symbolic_address(Bit32u context, Bit32u eip, Bit32u base) { static char buf[80]; #if 0 @@ -274,7 +274,7 @@ char* bx_dbg_symbolic_address(Bit32u context, Bit32u eip, Bit32u base) return buf; } -char* bx_dbg_disasm_symbolic_address(Bit32u eip, Bit32u base) +const char* bx_dbg_disasm_symbolic_address(Bit32u eip, Bit32u base) { static char buf[80]; @@ -293,7 +293,7 @@ char* bx_dbg_disasm_symbolic_address(Bit32u eip, Bit32u base) return buf; } -char* bx_dbg_symbolic_address_16bit(Bit32u eip, Bit32u cs) +const char* bx_dbg_symbolic_address_16bit(Bit32u eip, Bit32u cs) { // in 16-bit code, the segment selector and offset are combined into a // 20-bit linear address = (segment selector<<4) + offset. @@ -302,10 +302,10 @@ char* bx_dbg_symbolic_address_16bit(Bit32u eip, Bit32u cs) return bx_dbg_symbolic_address (0, eip+(cs<<4), 0); } -int bx_dbg_symbol_command(char* filename, bx_bool global, Bit32u offset) +int bx_dbg_symbol_command(const char* filename, bx_bool global, Bit32u offset) { - symbol_entry_t file(0, filename); - file.trim_quotes(); + symbol_entry_t file(0, filename); + file.trim_quotes(); // Install symbols in correct context (page table) // The file format should be @@ -378,7 +378,7 @@ static bool bx_dbg_strprefix(const char *s1, const char *s2) return strncmp(s1, s2, len)==0; } -void bx_dbg_info_symbols_command(char *Symbol) +void bx_dbg_info_symbols_command(const char *Symbol) { context_t* cntx = context_t::get_context(0); @@ -426,7 +426,7 @@ void bx_dbg_info_symbols_command(char *Symbol) } } -int bx_dbg_lbreakpoint_symbol_command(char *symbol) +int bx_dbg_lbreakpoint_symbol_command(const char *symbol) { context_t* cntx = context_t::get_context(0); if(!cntx) { diff --git a/bochs/config.cc b/bochs/config.cc index 63cc16eed..34e38d404 100755 --- a/bochs/config.cc +++ b/bochs/config.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: config.cc,v 1.176 2009-04-26 06:56:27 vruppert Exp $ +// $Id: config.cc,v 1.177 2009-05-03 19:21:38 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2002 MandrakeSoft S.A. @@ -2077,11 +2077,11 @@ static Bit32s parse_log_options(const char *context, char *loglev, char *param1) return 0; } -static int parse_debug_symbols(const char *context, char **params, int num_params) +static int parse_debug_symbols(const char *context, const char **params, int num_params) { #if BX_DEBUGGER Bit32u offset = 0; - char* filename = 0; + const char *filename = 0; while (num_params > 0) { @@ -2953,7 +2953,7 @@ static int parse_line_formatted(const char *context, int num_params, char *param #endif } else if (!strcmp(params[0], "debug_symbols")) { - if (parse_debug_symbols(context, params + 1, num_params - 1) < 0) { + if (parse_debug_symbols(context, (const char **)(params + 1), num_params - 1) < 0) { return -1; } } diff --git a/bochs/osdep.cc b/bochs/osdep.cc index 1db103de3..86967e809 100644 --- a/bochs/osdep.cc +++ b/bochs/osdep.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: osdep.cc,v 1.19 2009-01-16 18:18:57 sshwarts Exp $ +// $Id: osdep.cc,v 1.20 2009-05-03 19:21:38 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -75,8 +75,7 @@ int bx_vsnprintf (char *s, size_t maxlen, const char *format, va_list arg) do { if (endptr != NULL) *endptr = (char *) (end); \ return val; } while (0) -Bit64u -bx_strtoull (const char *nptr, char **endptr, int baseignore) +Bit64u bx_strtoull (const char *nptr, char **endptr, int baseignore) { int negative; /* The sign of the number. */ int exponent; /* Exponent of the number. */ @@ -114,29 +113,29 @@ bx_strtoull (const char *nptr, char **endptr, int baseignore) /* Get sign of the result. */ if (c == '-') - { - negative = 1; - c = *++cp; - } + { + negative = 1; + c = *++cp; + } else if (c == '+') c = *++cp; if (c < '0' || c > '9') - { - /* It is really a text we do not recognize. */ - RETURN (0, nptr); - } + { + /* It is really a text we do not recognize. */ + RETURN (0, nptr); + } /* First look whether we are faced with a hexadecimal number. */ if (c == '0' && tolower (cp[1]) == 'x') - { - /* Okay, it is a hexa-decimal number. Remember this and skip - the characters. BTW: hexadecimal numbers must not be - grouped. */ - base = 16; - cp += 2; - c = *cp; - } + { + /* Okay, it is a hexa-decimal number. Remember this and skip + the characters. BTW: hexadecimal numbers must not be + grouped. */ + base = 16; + cp += 2; + c = *cp; + } /* Record the start of the digits, in case we will check their grouping. */ start_of_digits = startp = cp; @@ -163,14 +162,14 @@ bx_strtoull (const char *nptr, char **endptr, int baseignore) startp = cp; dig_no = 0; while (1) - { + { if ((c >= '0' && c <= '9') || (base == 16 && tolower (c) >= 'a' && tolower (c) <= 'f')) ++dig_no; else break; c = *++cp; - } + } /* The whole string is parsed. Store the address of the next character. */ if (endptr) @@ -203,7 +202,7 @@ int main (int argc, char **argv) l = strtoul (buf, &endbuf, 10); printf ("As a long, %ld\n", l); printf ("Endbuf is at buf[%d]\n", endbuf-buf); - ll = bx_strtoull (buf, &endbuf, 10); + ll = bx_strtoull(buf, &endbuf, 10); printf ("As a long long, %lld\n", ll); printf ("Endbuf is at buf[%d]\n", endbuf-buf); } @@ -215,14 +214,12 @@ int main (int argc, char **argv) /* XXX use real strdup */ char *bx_strdup(const char *str) { - char *temp; + char *temp = (char*)malloc(strlen(str)+1); + sprintf(temp, "%s", str); + return temp; - temp = (char*)malloc(strlen(str)+1); - sprintf(temp, "%s", str); - return temp; - - // Well, I'm sure this isn't how strdup is REALLY implemented, - // but it works... + // Well, I'm sure this isn't how strdup is REALLY implemented, + // but it works... } #endif /* !BX_HAVE_STRDUP */ @@ -271,51 +268,48 @@ int bx_mkstemp(char *tpl) int fd_read(char *buffer, Bit32u offset, Bit32u bytes) { - OSErr err; - IOParam param; + OSErr err; + IOParam param; - param.ioRefNum=-5; // Refnum of the floppy disk driver - param.ioVRefNum=1; - param.ioPosMode=fsFromStart; - param.ioPosOffset=offset; - param.ioBuffer=buffer; - param.ioReqCount=bytes; - err = PBReadSync((union ParamBlockRec *)(¶m)); - return param.ioActCount; + param.ioRefNum=-5; // Refnum of the floppy disk driver + param.ioVRefNum=1; + param.ioPosMode=fsFromStart; + param.ioPosOffset=offset; + param.ioBuffer=buffer; + param.ioReqCount=bytes; + err = PBReadSync((union ParamBlockRec *)(¶m)); + return param.ioActCount; } int fd_write(char *buffer, Bit32u offset, Bit32u bytes) { - OSErr err; - IOParam param; + OSErr err; + IOParam param; - param.ioRefNum=-5; // Refnum of the floppy disk driver - param.ioVRefNum=1; - param.ioPosMode=fsFromStart; - param.ioPosOffset=offset; - param.ioBuffer=buffer; - param.ioReqCount=bytes; - err = PBWriteSync((union ParamBlockRec *)(¶m)); - return param.ioActCount; + param.ioRefNum=-5; // Refnum of the floppy disk driver + param.ioVRefNum=1; + param.ioPosMode=fsFromStart; + param.ioPosOffset=offset; + param.ioBuffer=buffer; + param.ioReqCount=bytes; + err = PBWriteSync((union ParamBlockRec *)(¶m)); + return param.ioActCount; } int fd_stat(struct stat *buf) { - OSErr err; - DrvSts status; - int result; + OSErr err; + DrvSts status; + int result = 0; - result = 0; - err = DriveStatus(1, &status); - if (status.diskInPlace <1 || status.diskInPlace > 2) - result = -1; - buf->st_mode = S_IFCHR; - return result; + err = DriveStatus(1, &status); + if (status.diskInPlace <1 || status.diskInPlace > 2) + result = -1; + buf->st_mode = S_IFCHR; + return result; } #endif /* BX_WITH_MACOS */ - - ////////////////////////////////////////////////////////////////////// // New functions to replace library functions // with OS-independent versions