Merge lp:~vjsamuel/drizzle/fix-casts-drizzle-client into lp:drizzle/7.0

Proposed by Vijay Samuel
Status: Superseded
Proposed branch: lp:~vjsamuel/drizzle/fix-casts-drizzle-client
Merge into: lp:drizzle/7.0
Diff against target: 247 lines (+33/-33)
1 file modified
client/drizzle.cc (+33/-33)
To merge this branch: bzr merge lp:~vjsamuel/drizzle/fix-casts-drizzle-client
Reviewer Review Type Date Requested Status
Olaf van der Spek (community) Needs Fixing
Drizzle Developers Pending
Review via email: mp+50951@code.launchpad.net

This proposal has been superseded by a proposal from 2011-02-23.

To post a comment you must log in.
Revision history for this message
Olaf van der Spek (olafvdspek) wrote :

> if (!(histfile_tmp= (char*) malloc(static_cast<uint32_t>(strlen(histfile) + 5))))
> const char * start = const_cast<const char *>(set);
> return (const_cast<const char *>(str));

Are these casts necessary at all?

review: Needs Fixing
Revision history for this message
Monty Taylor (mordred) wrote :

 - if (!(histfile_tmp= (char*) malloc(static_cast<uint32_t>(strlen(histfile) + 5))))

The internal one (static_cast<uint32_t> is not needed. strlen returns size_t which is the type malloc takes. However, (char *) can certainly be changed to use a c++ cast. (and don't even get me started on this needing to be a std::string instead of a malloc'd char *...

The other two are not - you do not need to const cast to _add_ const qualifiers, only to take them away.

2196. By Vijay Samuel

Merge removed unnecessary const casts

Unmerged revisions

2196. By Vijay Samuel

Merge removed unnecessary const casts

2195. By Vijay Samuel

Merge C++ style casts for drizzle client

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'client/drizzle.cc'
--- client/drizzle.cc 2011-02-22 04:09:52 +0000
+++ client/drizzle.cc 2011-02-23 17:56:22 +0000
@@ -1576,7 +1576,7 @@
1576 /* Check that delimiter does not contain a backslash */1576 /* Check that delimiter does not contain a backslash */
1577 if (! strstr(delimiter_str.c_str(), "\\"))1577 if (! strstr(delimiter_str.c_str(), "\\"))
1578 {1578 {
1579 delimiter= (char *)delimiter_str.c_str(); 1579 delimiter= const_cast<char *>(delimiter_str.c_str());
1580 }1580 }
1581 else1581 else
1582 {1582 {
@@ -1585,7 +1585,7 @@
1585 exit(-1);1585 exit(-1);
1586 }1586 }
1587 1587
1588 delimiter_length= (uint32_t)strlen(delimiter);1588 delimiter_length= static_cast<uint32_t>(strlen(delimiter));
1589 }1589 }
1590 if (vm.count("tee"))1590 if (vm.count("tee"))
1591 { 1591 {
@@ -1800,7 +1800,7 @@
1800 put_info(&output_buff[0], INFO_INFO, 0, 0);1800 put_info(&output_buff[0], INFO_INFO, 0, 0);
18011801
18021802
1803 initialize_readline((char *)current_prompt.c_str());1803 initialize_readline(const_cast<char *>(current_prompt.c_str()));
1804 if (!status.getBatch() && !quick)1804 if (!status.getBatch() && !quick)
1805 {1805 {
1806 /* read-history from file, default ~/.drizzle_history*/1806 /* read-history from file, default ~/.drizzle_history*/
@@ -1829,7 +1829,7 @@
1829 if (verbose)1829 if (verbose)
1830 tee_fprintf(stdout, _("Reading history-file %s\n"),histfile);1830 tee_fprintf(stdout, _("Reading history-file %s\n"),histfile);
1831 read_history(histfile);1831 read_history(histfile);
1832 if (!(histfile_tmp= (char*) malloc((uint32_t) strlen(histfile) + 5)))1832 if (!(histfile_tmp= (char*) malloc(strlen(histfile) + 5)))
1833 {1833 {
1834 fprintf(stderr, _("Couldn't allocate memory for temp histfile!\n"));1834 fprintf(stderr, _("Couldn't allocate memory for temp histfile!\n"));
1835 exit(1);1835 exit(1);
@@ -1947,12 +1947,12 @@
1947 char *tmp, *pagpoint;1947 char *tmp, *pagpoint;
1948 1948
19491949
1950 tmp= (char *) getenv("DRIZZLE_HOST");1950 tmp= const_cast<char *>(getenv("DRIZZLE_HOST"));
1951 if (tmp)1951 if (tmp)
1952 current_host.assign(tmp);1952 current_host.assign(tmp);
19531953
1954 pagpoint= getenv("PAGER");1954 pagpoint= getenv("PAGER");
1955 if (!((char*) (pagpoint)))1955 if (!(const_cast<char *>((pagpoint))))
1956 {1956 {
1957 pager.assign("stdout");1957 pager.assign("stdout");
1958 opt_nopager= 1;1958 opt_nopager= 1;
@@ -2102,14 +2102,14 @@
2102 return(NULL);2102 return(NULL);
2103 if ((end=strcont(name," \t")))2103 if ((end=strcont(name," \t")))
2104 {2104 {
2105 len=(uint32_t) (end - name);2105 len=static_cast<uint32_t>((end - name));
2106 while (isspace(*end))2106 while (isspace(*end))
2107 end++;2107 end++;
2108 if (!*end)2108 if (!*end)
2109 end=0; // no arguments to function2109 end=0; // no arguments to function
2110 }2110 }
2111 else2111 else
2112 len=(uint32_t) strlen(name);2112 len=static_cast<uint32_t>(strlen(name));
2113 }2113 }
21142114
2115 for (uint32_t i= 0; commands[i].getName(); i++)2115 for (uint32_t i= 0; commands[i].getName(); i++)
@@ -2139,7 +2139,7 @@
2139 return(0);2139 return(0);
2140 if (status.getAddToHistory() && line[0] && not_in_history(line))2140 if (status.getAddToHistory() && line[0] && not_in_history(line))
2141 add_history(line);2141 add_history(line);
2142 char *end_of_line=line+(uint32_t) strlen(line);2142 char *end_of_line= line + static_cast<uint32_t>(strlen(line));
21432143
2144 for (pos=out=line ; (inchar= (unsigned char) *pos) ; pos++)2144 for (pos=out=line ; (inchar= (unsigned char) *pos) ; pos++)
2145 {2145 {
@@ -2388,7 +2388,7 @@
2388 if (out != line || (buffer->length() > 0))2388 if (out != line || (buffer->length() > 0))
2389 {2389 {
2390 *out++='\n';2390 *out++='\n';
2391 uint32_t length=(uint32_t) (out-line);2391 uint32_t length= static_cast<uint32_t>((out-line));
2392 if ((buffer->length() + length) > opt_max_input_line)2392 if ((buffer->length() + length) > opt_max_input_line)
2393 {2393 {
2394 status.setExitStatus(1);2394 status.setExitStatus(1);
@@ -2779,7 +2779,7 @@
2779 {2779 {
2780 end= strcpy(buff, commands[i].getName());2780 end= strcpy(buff, commands[i].getName());
2781 end+= strlen(commands[i].getName());2781 end+= strlen(commands[i].getName());
2782 for (j= (int)strlen(commands[i].getName()); j < 10; j++)2782 for (j= static_cast<int>(strlen(commands[i].getName())); j < 10; j++)
2783 end= strcpy(end, " ")+1;2783 end= strcpy(end, " ")+1;
2784 if (commands[i].func)2784 if (commands[i].func)
2785 tee_fprintf(stdout, "%s(\\%c) %s\n", buff,2785 tee_fprintf(stdout, "%s(\\%c) %s\n", buff,
@@ -3174,7 +3174,7 @@
3174 if (quick)3174 if (quick)
3175 length=max(length,drizzle_column_size(field));3175 length=max(length,drizzle_column_size(field));
3176 else3176 else
3177 length=max(length,(uint32_t)drizzle_column_max_size(field));3177 length=max(length, static_cast<uint32_t>(drizzle_column_max_size(field)));
3178 if (length < 4 &&3178 if (length < 4 &&
3179 !(drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_NOT_NULL))3179 !(drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_NOT_NULL))
3180 {3180 {
@@ -3191,24 +3191,24 @@
3191 }3191 }
3192 drizzle_column_set_max_size(field, length);3192 drizzle_column_set_max_size(field, length);
31933193
3194 for (x=0; x< (length+2); x++)3194 for (x= 0; x < (length+2); x++)
3195 separator.append("-");3195 separator.append("-");
3196 separator.append("+");3196 separator.append("+");
3197 }3197 }
31983198
3199 tee_puts((char*) separator.c_str(), PAGER);3199 tee_puts(const_cast<char *>(separator.c_str()), PAGER);
3200 if (column_names)3200 if (column_names)
3201 {3201 {
3202 drizzle_column_seek(result,0);3202 drizzle_column_seek(result,0);
3203 (void) tee_fputs("|", PAGER);3203 (void) tee_fputs("|", PAGER);
3204 for (uint32_t off=0; (field = drizzle_column_next(result)) ; off++)3204 for (uint32_t off=0; (field = drizzle_column_next(result)) ; off++)
3205 {3205 {
3206 uint32_t name_length= (uint32_t) strlen(drizzle_column_name(field));3206 uint32_t name_length= static_cast<uint32_t>(strlen(drizzle_column_name(field)));
3207 uint32_t numcells= drizzled::utf8::char_length(drizzle_column_name(field));3207 uint32_t numcells= drizzled::utf8::char_length(drizzle_column_name(field));
3208 uint32_t display_length= drizzle_column_max_size(field) + name_length -3208 uint32_t display_length= drizzle_column_max_size(field) + name_length -
3209 numcells;3209 numcells;
3210 tee_fprintf(PAGER, " %-*s |",(int) min(display_length,3210 tee_fprintf(PAGER, " %-*s |",static_cast<int>(min(display_length,
3211 MAX_COLUMN_LENGTH),3211 MAX_COLUMN_LENGTH)),
3212 drizzle_column_name(field));3212 drizzle_column_name(field));
3213 num_flag[off]= ((drizzle_column_type(field) <= DRIZZLE_COLUMN_TYPE_LONGLONG) ||3213 num_flag[off]= ((drizzle_column_type(field) <= DRIZZLE_COLUMN_TYPE_LONGLONG) ||
3214 (drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_NEWDECIMAL));3214 (drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_NEWDECIMAL));
@@ -3232,7 +3232,7 @@
3232 }3232 }
3233 }3233 }
3234 (void) tee_fputs("\n", PAGER);3234 (void) tee_fputs("\n", PAGER);
3235 tee_puts((char*) separator.c_str(), PAGER);3235 tee_puts(const_cast<char *>(separator.c_str()), PAGER);
3236 }3236 }
32373237
3238 while (1)3238 while (1)
@@ -3300,7 +3300,7 @@
3300 else3300 else
3301 {3301 {
3302 buffer= cur[off];3302 buffer= cur[off];
3303 data_length= (uint32_t) lengths[off];3303 data_length= static_cast<uint32_t>(lengths[off]);
3304 }3304 }
33053305
3306 field= drizzle_column_next(result);3306 field= drizzle_column_next(result);
@@ -3359,7 +3359,7 @@
3359 if (quick)3359 if (quick)
3360 length= max(length, drizzle_column_size(field));3360 length= max(length, drizzle_column_size(field));
3361 else3361 else
3362 length= max(length, (uint32_t)drizzle_column_max_size(field));3362 length= max(length, static_cast<uint32_t>(drizzle_column_max_size(field)));
33633363
3364 if (length < 4 &&3364 if (length < 4 &&
3365 !(drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_NOT_NULL))3365 !(drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_NOT_NULL))
@@ -3408,19 +3408,19 @@
34083408
3409 if (right_justified)3409 if (right_justified)
3410 for (i= data_length; i < total_bytes_to_send; i++)3410 for (i= data_length; i < total_bytes_to_send; i++)
3411 tee_putc((int)' ', PAGER);3411 tee_putc(static_cast<int>(' '), PAGER);
34123412
3413 for (i= 0, p= data; i < data_length; i+= 1, p+= 1)3413 for (i= 0, p= data; i < data_length; i+= 1, p+= 1)
3414 {3414 {
3415 if (*p == '\0')3415 if (*p == '\0')
3416 tee_putc((int)' ', PAGER);3416 tee_putc(static_cast<int>(' '), PAGER);
3417 else3417 else
3418 tee_putc((int)*p, PAGER);3418 tee_putc(static_cast<int>(*p), PAGER);
3419 }3419 }
34203420
3421 if (! right_justified)3421 if (! right_justified)
3422 for (i= data_length; i < total_bytes_to_send; i++)3422 for (i= data_length; i < total_bytes_to_send; i++)
3423 tee_putc((int)' ', PAGER);3423 tee_putc(static_cast<int>(' '), PAGER);
3424}3424}
34253425
34263426
@@ -3463,8 +3463,8 @@
3463 for (uint32_t off=0; off < drizzle_result_column_count(result); off++)3463 for (uint32_t off=0; off < drizzle_result_column_count(result); off++)
3464 {3464 {
3465 field= drizzle_column_next(result);3465 field= drizzle_column_next(result);
3466 tee_fprintf(PAGER, "%*s: ",(int) max_length,drizzle_column_name(field));3466 tee_fprintf(PAGER, "%*s: ",static_cast<int>(max_length) ,drizzle_column_name(field));
3467 tee_fprintf(PAGER, "%s\n",cur[off] ? (char*) cur[off] : "NULL");3467 tee_fprintf(PAGER, "%s\n",cur[off] ? const_cast<char *>(cur[off]) : "NULL");
3468 }3468 }
3469 if (quick)3469 if (quick)
3470 drizzle_row_free(result, cur);3470 drizzle_row_free(result, cur);
@@ -3501,7 +3501,7 @@
3501 warning.3501 warning.
3502 */3502 */
3503 if (!cur || (num_rows == 1 &&3503 if (!cur || (num_rows == 1 &&
3504 error_code == (uint32_t) strtoul(cur[1], NULL, 10)))3504 error_code == static_cast<uint32_t>(strtoul(cur[1], NULL, 10))))
3505 {3505 {
3506 goto end;3506 goto end;
3507 }3507 }
@@ -3955,7 +3955,7 @@
3955 }3955 }
3956 }3956 }
3957 strncpy(delimiter, tmp, sizeof(delimiter) - 1);3957 strncpy(delimiter, tmp, sizeof(delimiter) - 1);
3958 delimiter_length= (int)strlen(delimiter);3958 delimiter_length= static_cast<int>(strlen(delimiter));
3959 delimiter_str= delimiter;3959 delimiter_str= delimiter;
3960 return 0;3960 return 0;
3961}3961}
@@ -4180,9 +4180,9 @@
4180 drizzle_con_options_t options= (drizzle_con_options_t) (use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);4180 drizzle_con_options_t options= (drizzle_con_options_t) (use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
4181#endif4181#endif
41824182
4183 if (drizzle_con_add_tcp(&drizzle, &con, (char *)host.c_str(),4183 if (drizzle_con_add_tcp(&drizzle, &con, const_cast<char *>(host.c_str()),
4184 opt_drizzle_port, (char *)user.c_str(),4184 opt_drizzle_port, const_cast<char *>(user.c_str()),
4185 (char *)password.c_str(), (char *)database.c_str(),4185 const_cast<char *>(password.c_str()), const_cast<char *>(database.c_str()),
4186 options) == NULL)4186 options) == NULL)
4187 {4187 {
4188 (void) put_error(&con, NULL);4188 (void) put_error(&con, NULL);
@@ -4781,14 +4781,14 @@
47814781
4782static const char * strcont(const char *str, const char *set)4782static const char * strcont(const char *str, const char *set)
4783{4783{
4784 const char * start = (const char *) set;4784 const char * start= set;
47854785
4786 while (*str)4786 while (*str)
4787 {4787 {
4788 while (*set)4788 while (*set)
4789 {4789 {
4790 if (*set++ == *str)4790 if (*set++ == *str)
4791 return ((const char*) str);4791 return (str);
4792 }4792 }
4793 set=start; str++;4793 set=start; str++;
4794 }4794 }

Subscribers

People subscribed via source and target branches