- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在研究一些示例,但不断收到这些 Address Sanitizer 堆缓冲区溢出错误。我一生都无法弄清楚潜在的溢出在哪里:
bool detectCapitalUse(char * word){
int CapitalLet = 0;
int WordLen = sizeof(word)/sizeof(char);
bool result = 0;
for (int i = 0; i < WordLen; i++)
{
if (word[i] >= 'A' && word[i] <= 'Z' )
{
CapitalLet++;
}
}
if( CapitalLet == WordLen )
{
result = 1;
}
else if ((CapitalLet == 1) && (word[0] >= 'A' && word[0] <= 'Z'))
{
result = 1;
}
else if (CapitalLet == 0 )
{
result = 1;
}
else
{
result = 0;
}
return result;
}
编辑:这是完整的错误消息。
=================================================================
==31==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000017 at pc 0x000000401850 bp 0x7ffcd5e90680 sp 0x7ffcd5e90670
READ of size 1 at 0x602000000017 thread T0
#2 0x7f2bb38ea82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
0x602000000017 is located 0 bytes to the right of 7-byte region [0x602000000010,0x602000000017)
allocated by thread T0 here:
#0 0x7f2bb4905f88 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10bf88)
#4 0x7f2bb38ea82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
Shadow bytes around the buggy address:
0x0c047fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c047fff8000: fa fa[07]fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8010: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==31==ABORTING
最佳答案
因为您的代码中没有使用 heap memory ,没有什么可能导致堆溢出,但可以解决的问题在这里:
int WordLen = sizeof(word)/sizeof(char);.
在论证中
(char * word)
word
在作为参数传递时衰减为指针,所以
sizeof(word)
真的会返回一个指针的大小(32 位寻址的 4 个字节),而不是您可能传递的数组的大小。顺便说一句,
sizeof(char)
总是
1
根据定义。
int WordLen = strlen(word);
更改这一行可以让您的代码按我认为的那样工作。我使用以下调用方法对其进行了测试:
int main(void)
{
char word[] = {"this is A string"};
bool res = detectCapitalUse(word);
return 0;
}
一个警告 :
关于c - LeetCode : Address Sanitizer Violations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63909823/
我正在解决以下leetcode问题:。。递归解是平凡的,所以我试着想出迭代解。下面是我的解决方案:。问题是:代码相对冗长,难以阅读。我的想法是跟踪从顶部到当前节点的整个路径。但这与标准DFS不同,因为
我正在解决以下leetcode问题:。。递归的解决方案是微不足道的,所以我试图拿出迭代的解决方案。下面是我的解决方案:。问题是:代码相对冗长,难以阅读。我的想法是跟踪从顶部到当前节点的整个路径。但这与
我正在处理 'Two Sum' problem in Leetcode . 我确信这段代码是正确的,我已经在 Repl 中对其进行了测试,它看起来是正确的,但 Leetcode 给了我一个错误。 这是
我正在研究 leetcode“762. 二进制表示中设置位的质数”,并且我测试了我的代码在 Jupiter Notebook 上运行良好,当我迁移到 leetcode 时,它显示 null 作为最
题干 请写出一个高效的在m*n矩阵中判断目标值是否存在的算法,矩阵具有如下特征: 每一行的数字都从左到右排序 每一行的第一个数字都比上一行最后一个数字大 用例 例如对于下面矩阵: [ [1,
LeetCode Monotone Stack Summary 单调栈小结 所谓的单调栈 Monotone Stack,就是栈内元素都是单调递增或者单调递减的,有时候需要严格的单调递增或递减,根据
第一题: 合并二叉树 LeetCode 617 : 合并二叉树 描述: 给定两个二叉树,想象当你将它们中的一个覆盖到另一个上时,两个二叉树的一些节点便会重叠。 你需要将他们合并为一个新的二叉树。合并的
和为k的子数组 LeetCode 560 和为k的不重复子数组个数(包含不连续): 和为k的子数组 LeetCode 560 Example 1: Input:nums=[1,1,1],k=2 Ou
1.题目描述: 难度:简单 描述: 罗马数字包含以下七种字符: I, V, X, L,C,D 和 M。 字符 数值 I 1 V 5 X
1.题目描述: 难度:简单 描述: 给你一个整数 x ,如果 x 是一个回文整数,返回 true ;否则,返回 false 。 回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。 例如,1
一、题目描述 难道:简单 描述: 给你一个 升序排列 的数组 nums ,请你 原地 删除重复出现的元素,使每个元素 只出现一次 ,返回删除后数组的新长度。元素的 相对顺序 应该保持 一致 。 由于在
一、题目描述 难度:简单 描述: 编写一个函数来查找字符串数组中的最长公共前缀。 如果不存在公共前缀,返回空字符串 “”。 示例 1: 输入:strs = ["flower","flow","flig
一、题目描述 难度:简单 描述: 将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例 1: 输入:l1 = [1,2,4], l2 = [1,3,4
@TOC 题目描述 给定一个只包括 ‘(’,‘)’,‘{’,‘}’,‘[’,‘]’ 的字符串 s ,判断字符串是否有效。 有效字符串需满足: 左括号必须用相同类型的右括号闭合。 左括号必须以正确的顺序
我已经在 Repl.it 网站上解决了这个问题,但是当我在 LeetCode 上提交代码时,它给出了一个 typeError,我将把它粘贴在这里: Line 29 in solution.js
var merge = function(nums1, m, nums2, n) { //contcating two array let array = nums2.concat(
我正在做以下leetCode问题:https://leetcode.com/problems/add-two-numbers/ 我不确定为什么我的一个测试用例失败了 所以问题是 You are giv
我正在尝试完成 Leetcode 上的 189. 旋转数组问题。这是我写的代码: class Solution(object): def rotate(self, nums, k):
该函数将反向打印链表的节点: void recur(ListNode head) { if(head == null) return; recur(head.next); tm
我正在尝试完成 Leetcode 上的 189. 旋转数组问题。这是我写的代码: class Solution(object): def rotate(self, nums, k):
我是一名优秀的程序员,十分优秀!