Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: components/crash/app/breakpad_linux.cc

Issue 1151503007: Remove redundant functions my_strncpy() and my_strncat() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // For linux_syscall_support.h. This makes it safe to call embedded system 5 // For linux_syscall_support.h. This makes it safe to call embedded system
6 // calls when in seccomp mode. 6 // calls when in seccomp mode.
7 7
8 #include "components/crash/app/breakpad_linux.h" 8 #include "components/crash/app/breakpad_linux.h"
9 9
10 #include <fcntl.h> 10 #include <fcntl.h>
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 159 }
160 160
161 // uint64_t version of my_uitos() from 161 // uint64_t version of my_uitos() from
162 // breakpad/src/common/linux/linux_libc_support.h. Convert a non-negative 162 // breakpad/src/common/linux/linux_libc_support.h. Convert a non-negative
163 // integer to a string (not null-terminated). 163 // integer to a string (not null-terminated).
164 void my_uint64tos(char* output, uint64_t i, unsigned i_len) { 164 void my_uint64tos(char* output, uint64_t i, unsigned i_len) {
165 for (unsigned index = i_len; index; --index, i /= 10) 165 for (unsigned index = i_len; index; --index, i /= 10)
166 output[index - 1] = '0' + (i % 10); 166 output[index - 1] = '0' + (i % 10);
167 } 167 }
168 168
169 #if defined(OS_ANDROID)
170 char* my_strncpy(char* dst, const char* src, size_t len) {
171 int i = len;
172 char* p = dst;
173 if (!dst || !src)
174 return dst;
175 while (i != 0 && *src != '\0') {
176 *p++ = *src++;
177 i--;
178 }
179 while (i != 0) {
180 *p++ = '\0';
181 i--;
182 }
183 return dst;
184 }
185
186 char* my_strncat(char *dest, const char* src, size_t len) {
187 char* ret = dest;
188 while (*dest)
189 dest++;
190 while (len--)
191 if (!(*dest++ = *src++))
192 return ret;
193 *dest = 0;
194 return ret;
195 }
196 #endif
197
198 #if !defined(OS_CHROMEOS) 169 #if !defined(OS_CHROMEOS)
199 bool my_isxdigit(char c) { 170 bool my_isxdigit(char c) {
200 return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f'); 171 return (c >= '0' && c <= '9') || ((c | 0x20) >= 'a' && (c | 0x20) <= 'f');
201 } 172 }
202 #endif 173 #endif
203 174
204 size_t LengthWithoutTrailingSpaces(const char* str, size_t len) { 175 size_t LengthWithoutTrailingSpaces(const char* str, size_t len) {
205 while (len > 0 && str[len - 1] == ' ') { 176 while (len > 0 && str[len - 1] == ' ') {
206 len--; 177 len--;
207 } 178 }
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 writer.AddBoundary(); 1506 writer.AddBoundary();
1536 writer.AddFileContents(g_log_msg, log_data, log_size); 1507 writer.AddFileContents(g_log_msg, log_data, log_size);
1537 #endif 1508 #endif
1538 writer.AddEnd(); 1509 writer.AddEnd();
1539 writer.Flush(); 1510 writer.Flush();
1540 1511
1541 IGNORE_RET(sys_close(temp_file_fd)); 1512 IGNORE_RET(sys_close(temp_file_fd));
1542 1513
1543 #if defined(OS_ANDROID) 1514 #if defined(OS_ANDROID)
1544 if (info.filename) { 1515 if (info.filename) {
1545 int filename_length = my_strlen(info.filename); 1516 size_t filename_length = my_strlen(info.filename);
1546 1517
1547 // If this was a file, we need to copy it to the right place and use the 1518 // If this was a file, we need to copy it to the right place and use the
1548 // right file name so it gets uploaded by the browser. 1519 // right file name so it gets uploaded by the browser.
1549 const char msg[] = "Output crash dump file:"; 1520 const char msg[] = "Output crash dump file:";
1550 WriteLog(msg, sizeof(msg) - 1); 1521 WriteLog(msg, sizeof(msg) - 1);
1551 WriteLog(info.filename, filename_length - 1); 1522 WriteLog(info.filename, filename_length);
hashimoto 2015/06/05 07:02:43 WriteLog's Android implementation ignores the seco
1552 1523
1553 char pid_buf[kUint64StringSize]; 1524 char pid_buf[kUint64StringSize];
1554 uint64_t pid_str_length = my_uint64_len(info.pid); 1525 size_t pid_str_length = my_uint64_len(info.pid);
1555 my_uint64tos(pid_buf, info.pid, pid_str_length); 1526 my_uint64tos(pid_buf, info.pid, pid_str_length);
1527 pid_buf[pid_str_length] = 0; // my_uint64tos() doesn't null-terminate.
1556 1528
1557 // -1 because we won't need the null terminator on the original filename. 1529 size_t done_filename_len = filename_length + pid_str_length + 1;
1558 unsigned done_filename_len = filename_length - 1 + pid_str_length;
hashimoto 2015/06/05 07:02:43 IIUC the existing code writes more bytes than allo
Lei Zhang 2015/06/05 18:24:09 Yes, it's full of fail. :(
1559 char* done_filename = reinterpret_cast<char*>( 1530 char* done_filename = reinterpret_cast<char*>(
1560 allocator.Alloc(done_filename_len)); 1531 allocator.Alloc(done_filename_len));
1561 // Rename the file such that the pid is the suffix in order signal to other 1532 // Rename the file such that the pid is the suffix in order signal to other
1562 // processes that the minidump is complete. The advantage of using the pid 1533 // processes that the minidump is complete. The advantage of using the pid
1563 // as the suffix is that it is trivial to associate the minidump with the 1534 // as the suffix is that it is trivial to associate the minidump with the
1564 // crashed process. 1535 // crashed process.
1565 // Finally, note strncpy prevents null terminators from 1536 my_strlcpy(done_filename, info.filename, done_filename_len);
1566 // being copied. Pad the rest with 0's. 1537 my_strlcat(done_filename, pid_buf, done_filename_len);
1567 my_strncpy(done_filename, info.filename, done_filename_len);
1568 // Append the suffix a null terminator should be added.
1569 my_strncat(done_filename, pid_buf, pid_str_length);
1570 // Rename the minidump file to signal that it is complete. 1538 // Rename the minidump file to signal that it is complete.
1571 if (rename(info.filename, done_filename)) { 1539 if (rename(info.filename, done_filename)) {
1572 const char failed_msg[] = "Failed to rename:"; 1540 const char failed_msg[] = "Failed to rename:";
1573 WriteLog(failed_msg, sizeof(failed_msg) - 1); 1541 WriteLog(failed_msg, sizeof(failed_msg) - 1);
1574 WriteLog(info.filename, filename_length - 1); 1542 WriteLog(info.filename, filename_length);
1575 const char to_msg[] = "to"; 1543 const char to_msg[] = "to";
1576 WriteLog(to_msg, sizeof(to_msg) - 1); 1544 WriteLog(to_msg, sizeof(to_msg) - 1);
1577 WriteLog(done_filename, done_filename_len - 1); 1545 WriteLog(done_filename, done_filename_len);
Lei Zhang 2015/06/05 18:24:09 The -1 should remain here, right?
hashimoto 2015/06/06 02:11:05 Ugh, you're right. Fixed.
1578 } 1546 }
1579 } 1547 }
1580 #endif 1548 #endif
1581 1549
1582 if (!info.upload) 1550 if (!info.upload)
1583 return; 1551 return;
1584 1552
1585 const pid_t child = sys_fork(); 1553 const pid_t child = sys_fork();
1586 if (!child) { 1554 if (!child) {
1587 // Spawned helper process. 1555 // Spawned helper process.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1739 } 1707 }
1740 } 1708 }
1741 } 1709 }
1742 #endif // OS_ANDROID 1710 #endif // OS_ANDROID
1743 1711
1744 bool IsCrashReporterEnabled() { 1712 bool IsCrashReporterEnabled() {
1745 return g_is_crash_reporter_enabled; 1713 return g_is_crash_reporter_enabled;
1746 } 1714 }
1747 1715
1748 } // namespace breakpad 1716 } // namespace breakpad
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698