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
1=== modified file 'client/drizzle.cc'
2--- client/drizzle.cc 2011-02-22 04:09:52 +0000
3+++ client/drizzle.cc 2011-02-23 17:56:22 +0000
4@@ -1576,7 +1576,7 @@
5 /* Check that delimiter does not contain a backslash */
6 if (! strstr(delimiter_str.c_str(), "\\"))
7 {
8- delimiter= (char *)delimiter_str.c_str();
9+ delimiter= const_cast<char *>(delimiter_str.c_str());
10 }
11 else
12 {
13@@ -1585,7 +1585,7 @@
14 exit(-1);
15 }
16
17- delimiter_length= (uint32_t)strlen(delimiter);
18+ delimiter_length= static_cast<uint32_t>(strlen(delimiter));
19 }
20 if (vm.count("tee"))
21 {
22@@ -1800,7 +1800,7 @@
23 put_info(&output_buff[0], INFO_INFO, 0, 0);
24
25
26- initialize_readline((char *)current_prompt.c_str());
27+ initialize_readline(const_cast<char *>(current_prompt.c_str()));
28 if (!status.getBatch() && !quick)
29 {
30 /* read-history from file, default ~/.drizzle_history*/
31@@ -1829,7 +1829,7 @@
32 if (verbose)
33 tee_fprintf(stdout, _("Reading history-file %s\n"),histfile);
34 read_history(histfile);
35- if (!(histfile_tmp= (char*) malloc((uint32_t) strlen(histfile) + 5)))
36+ if (!(histfile_tmp= (char*) malloc(strlen(histfile) + 5)))
37 {
38 fprintf(stderr, _("Couldn't allocate memory for temp histfile!\n"));
39 exit(1);
40@@ -1947,12 +1947,12 @@
41 char *tmp, *pagpoint;
42
43
44- tmp= (char *) getenv("DRIZZLE_HOST");
45+ tmp= const_cast<char *>(getenv("DRIZZLE_HOST"));
46 if (tmp)
47 current_host.assign(tmp);
48
49 pagpoint= getenv("PAGER");
50- if (!((char*) (pagpoint)))
51+ if (!(const_cast<char *>((pagpoint))))
52 {
53 pager.assign("stdout");
54 opt_nopager= 1;
55@@ -2102,14 +2102,14 @@
56 return(NULL);
57 if ((end=strcont(name," \t")))
58 {
59- len=(uint32_t) (end - name);
60+ len=static_cast<uint32_t>((end - name));
61 while (isspace(*end))
62 end++;
63 if (!*end)
64 end=0; // no arguments to function
65 }
66 else
67- len=(uint32_t) strlen(name);
68+ len=static_cast<uint32_t>(strlen(name));
69 }
70
71 for (uint32_t i= 0; commands[i].getName(); i++)
72@@ -2139,7 +2139,7 @@
73 return(0);
74 if (status.getAddToHistory() && line[0] && not_in_history(line))
75 add_history(line);
76- char *end_of_line=line+(uint32_t) strlen(line);
77+ char *end_of_line= line + static_cast<uint32_t>(strlen(line));
78
79 for (pos=out=line ; (inchar= (unsigned char) *pos) ; pos++)
80 {
81@@ -2388,7 +2388,7 @@
82 if (out != line || (buffer->length() > 0))
83 {
84 *out++='\n';
85- uint32_t length=(uint32_t) (out-line);
86+ uint32_t length= static_cast<uint32_t>((out-line));
87 if ((buffer->length() + length) > opt_max_input_line)
88 {
89 status.setExitStatus(1);
90@@ -2779,7 +2779,7 @@
91 {
92 end= strcpy(buff, commands[i].getName());
93 end+= strlen(commands[i].getName());
94- for (j= (int)strlen(commands[i].getName()); j < 10; j++)
95+ for (j= static_cast<int>(strlen(commands[i].getName())); j < 10; j++)
96 end= strcpy(end, " ")+1;
97 if (commands[i].func)
98 tee_fprintf(stdout, "%s(\\%c) %s\n", buff,
99@@ -3174,7 +3174,7 @@
100 if (quick)
101 length=max(length,drizzle_column_size(field));
102 else
103- length=max(length,(uint32_t)drizzle_column_max_size(field));
104+ length=max(length, static_cast<uint32_t>(drizzle_column_max_size(field)));
105 if (length < 4 &&
106 !(drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_NOT_NULL))
107 {
108@@ -3191,24 +3191,24 @@
109 }
110 drizzle_column_set_max_size(field, length);
111
112- for (x=0; x< (length+2); x++)
113+ for (x= 0; x < (length+2); x++)
114 separator.append("-");
115 separator.append("+");
116 }
117
118- tee_puts((char*) separator.c_str(), PAGER);
119+ tee_puts(const_cast<char *>(separator.c_str()), PAGER);
120 if (column_names)
121 {
122 drizzle_column_seek(result,0);
123 (void) tee_fputs("|", PAGER);
124 for (uint32_t off=0; (field = drizzle_column_next(result)) ; off++)
125 {
126- uint32_t name_length= (uint32_t) strlen(drizzle_column_name(field));
127+ uint32_t name_length= static_cast<uint32_t>(strlen(drizzle_column_name(field)));
128 uint32_t numcells= drizzled::utf8::char_length(drizzle_column_name(field));
129 uint32_t display_length= drizzle_column_max_size(field) + name_length -
130 numcells;
131- tee_fprintf(PAGER, " %-*s |",(int) min(display_length,
132- MAX_COLUMN_LENGTH),
133+ tee_fprintf(PAGER, " %-*s |",static_cast<int>(min(display_length,
134+ MAX_COLUMN_LENGTH)),
135 drizzle_column_name(field));
136 num_flag[off]= ((drizzle_column_type(field) <= DRIZZLE_COLUMN_TYPE_LONGLONG) ||
137 (drizzle_column_type(field) == DRIZZLE_COLUMN_TYPE_NEWDECIMAL));
138@@ -3232,7 +3232,7 @@
139 }
140 }
141 (void) tee_fputs("\n", PAGER);
142- tee_puts((char*) separator.c_str(), PAGER);
143+ tee_puts(const_cast<char *>(separator.c_str()), PAGER);
144 }
145
146 while (1)
147@@ -3300,7 +3300,7 @@
148 else
149 {
150 buffer= cur[off];
151- data_length= (uint32_t) lengths[off];
152+ data_length= static_cast<uint32_t>(lengths[off]);
153 }
154
155 field= drizzle_column_next(result);
156@@ -3359,7 +3359,7 @@
157 if (quick)
158 length= max(length, drizzle_column_size(field));
159 else
160- length= max(length, (uint32_t)drizzle_column_max_size(field));
161+ length= max(length, static_cast<uint32_t>(drizzle_column_max_size(field)));
162
163 if (length < 4 &&
164 !(drizzle_column_flags(field) & DRIZZLE_COLUMN_FLAGS_NOT_NULL))
165@@ -3408,19 +3408,19 @@
166
167 if (right_justified)
168 for (i= data_length; i < total_bytes_to_send; i++)
169- tee_putc((int)' ', PAGER);
170+ tee_putc(static_cast<int>(' '), PAGER);
171
172 for (i= 0, p= data; i < data_length; i+= 1, p+= 1)
173 {
174 if (*p == '\0')
175- tee_putc((int)' ', PAGER);
176+ tee_putc(static_cast<int>(' '), PAGER);
177 else
178- tee_putc((int)*p, PAGER);
179+ tee_putc(static_cast<int>(*p), PAGER);
180 }
181
182 if (! right_justified)
183 for (i= data_length; i < total_bytes_to_send; i++)
184- tee_putc((int)' ', PAGER);
185+ tee_putc(static_cast<int>(' '), PAGER);
186 }
187
188
189@@ -3463,8 +3463,8 @@
190 for (uint32_t off=0; off < drizzle_result_column_count(result); off++)
191 {
192 field= drizzle_column_next(result);
193- tee_fprintf(PAGER, "%*s: ",(int) max_length,drizzle_column_name(field));
194- tee_fprintf(PAGER, "%s\n",cur[off] ? (char*) cur[off] : "NULL");
195+ tee_fprintf(PAGER, "%*s: ",static_cast<int>(max_length) ,drizzle_column_name(field));
196+ tee_fprintf(PAGER, "%s\n",cur[off] ? const_cast<char *>(cur[off]) : "NULL");
197 }
198 if (quick)
199 drizzle_row_free(result, cur);
200@@ -3501,7 +3501,7 @@
201 warning.
202 */
203 if (!cur || (num_rows == 1 &&
204- error_code == (uint32_t) strtoul(cur[1], NULL, 10)))
205+ error_code == static_cast<uint32_t>(strtoul(cur[1], NULL, 10))))
206 {
207 goto end;
208 }
209@@ -3955,7 +3955,7 @@
210 }
211 }
212 strncpy(delimiter, tmp, sizeof(delimiter) - 1);
213- delimiter_length= (int)strlen(delimiter);
214+ delimiter_length= static_cast<int>(strlen(delimiter));
215 delimiter_str= delimiter;
216 return 0;
217 }
218@@ -4180,9 +4180,9 @@
219 drizzle_con_options_t options= (drizzle_con_options_t) (use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
220 #endif
221
222- if (drizzle_con_add_tcp(&drizzle, &con, (char *)host.c_str(),
223- opt_drizzle_port, (char *)user.c_str(),
224- (char *)password.c_str(), (char *)database.c_str(),
225+ if (drizzle_con_add_tcp(&drizzle, &con, const_cast<char *>(host.c_str()),
226+ opt_drizzle_port, const_cast<char *>(user.c_str()),
227+ const_cast<char *>(password.c_str()), const_cast<char *>(database.c_str()),
228 options) == NULL)
229 {
230 (void) put_error(&con, NULL);
231@@ -4781,14 +4781,14 @@
232
233 static const char * strcont(const char *str, const char *set)
234 {
235- const char * start = (const char *) set;
236+ const char * start= set;
237
238 while (*str)
239 {
240 while (*set)
241 {
242 if (*set++ == *str)
243- return ((const char*) str);
244+ return (str);
245 }
246 set=start; str++;
247 }

Subscribers

People subscribed via source and target branches