- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
下面的简单程序对我来说是段错误:
#include <string.h>
int main()
{
void* voidp = NULL;
char zeroes[sizeof(void*)];
memset(zeroes, 0, sizeof(void*));
int res = memcmp(&voidp, zeroes, sizeof(void*));
return 0;
}
调试器显示段错误在 memcmp 中。
我的机器运行的是 64 位 Ubuntu 8.04,gcc 版本是 4.2.4。
它在我试过的其他机器(32 位或 64 位)上运行良好。
关于正在发生的事情有什么想法吗?
更新:这是汇编代码:
.file "failed.c"
.text
.globl main
.type main, @function
main:
.LFB2:
pushq %rbp
.LCFI0:
movq %rsp, %rbp
.LCFI1:
subq $32, %rsp
.LCFI2:
movq %fs:40, %rax
movq %rax, -8(%rbp)
xorl %eax, %eax
movq $0, -32(%rbp)
leaq -16(%rbp), %rdi
movl $8, %edx
movl $0, %esi
call memset
leaq -16(%rbp), %rsi
leaq -32(%rbp), %rdi
movl $8, %edx
call memcmp
movl %eax, -20(%rbp)
movl $0, %eax
movq -8(%rbp), %rdx
xorq %fs:40, %rdx
je .L3
call __stack_chk_fail
.L3:
leave
ret
.LFE2:
.size main, .-main
.section .eh_frame,"a",@progbits
.Lframe1:
.long .LECIE1-.LSCIE1
.LSCIE1:
.long 0x0
.byte 0x1
.string "zR"
.uleb128 0x1
.sleb128 -8
.byte 0x10
.uleb128 0x1
.byte 0x3
.byte 0xc
.uleb128 0x7
.uleb128 0x8
.byte 0x90
.uleb128 0x1
.align 8
.LECIE1:
.LSFDE1:
.long .LEFDE1-.LASFDE1
.LASFDE1:
.long .LASFDE1-.Lframe1
.long .LFB2
.long .LFE2-.LFB2
.uleb128 0x0
.byte 0x4
.long .LCFI0-.LFB2
.byte 0xe
.uleb128 0x10
.byte 0x86
.uleb128 0x2
.byte 0x4
.long .LCFI1-.LCFI0
.byte 0xd
.uleb128 0x6
.align 8
.LEFDE1:
.ident "GCC: (GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4)"
.section .note.GNU-stack,"",@progbits
更新:(这应该是评论,但不适合 600 个字符)。当我尝试 sudo apt-get install libc6
时,我得到:
Reading package lists... Done
Building dependency tree
Reading state information... Done
libc6 is already the newest version.
You might want to run `apt-get -f install' to correct these:
The following packages have unmet dependencies:
libc6: Depends: libc-bin (= 2.11.1-0ubuntu7.5) but it is not installable
Depends: findutils (>= 4.4.0-2ubuntu2) but 4.2.32-1ubuntu2 is to be installed
libc6-dev: Depends: libc6 (= 2.7-10ubuntu5) but 2.11.1-0ubuntu7.5 is to be installed
libc6-i386: Depends: libc6 (= 2.7-10ubuntu5) but 2.11.1-0ubuntu7.5 is to be installed
locales: Depends: belocs-locales-bin (>= 2.4-2.2ubuntu2) but it is not going to be installed
locales-all: Depends: glibc-2.11-1 but it is not installable
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
最后,如果我尝试执行 sudo apt-get -f install
,我得到:
Reading package lists... Done
Building dependency tree
Reading state information... Done
libc6 is already the newest version.
You might want to run `apt-get -f install' to correct these:
The following packages have unmet dependencies:
libc6: Depends: libc-bin (= 2.11.1-0ubuntu7.5) but it is not installable
Depends: findutils (>= 4.4.0-2ubuntu2) but 4.2.32-1ubuntu2 is to be installed
libc6-dev: Depends: libc6 (= 2.7-10ubuntu5) but 2.11.1-0ubuntu7.5 is to be installed
libc6-i386: Depends: libc6 (= 2.7-10ubuntu5) but 2.11.1-0ubuntu7.5 is to be installed
locales: Depends: belocs-locales-bin (>= 2.4-2.2ubuntu2) but it is not going to be installed
locales-all: Depends: glibc-2.11-1 but it is not installable
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
botond@adaptive1:~$ sudo apt-get -f install
Reading package lists... Done
Building dependency tree
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
vim-runtime linux-libc-dev mysql-common openssh-blacklist
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
libdns35
The following packages will be REMOVED:
adduser apparmor apparmor-utils apt apt-file apt-utils aptitude at atop base-files base-passwd bash bash-completion bind9-host binutils bsdmainutils bsdutils bzip2 command-not-found
console-setup console-terminus console-tools coreutils cpio cpp cpp-4.2 cron curl dash debconf debconf-i18n debianutils dhcp3-client dhcp3-common diff dmidecode dmsetup dnsutils dosfstools dpkg
e2fslibs e2fsprogs ed eject ethtool fdutils file findutils friendly-recovery ftp fuse-utils g++ g++-4.2 g++-4.2-multilib gcc gcc-4.2 gcc-4.2-multilib gdb-minimal gettext-base gnupg gpgv grep
groff-base grub gzip hdparm hostname ifupdown info initramfs-tools initscripts inputattach iproute iptables iputils-arping iputils-ping iputils-tracepath klogd laptop-detect less lib32gcc1
lib32gomp1 lib32stdc++6 libacl1 libapr1 libaprutil1 libapt-pkg-perl libatm1 libattr1 libbind9-30 libblkid1 libboost-dev libbz2-1.0 libc6 libc6-dev libc6-dev-i386 libc6-i386 libcap1
libck-connector0 libcomerr2 libconfig-file-perl libconsole libcurl3 libcurl3-gnutls libcwidget3 libdb-dev libdb4.6 libdb4.6++ libdb4.6++-dev libdb4.6-dev libdbd-mysql-perl libdbi-perl
libdbus-1-3 libdevmapper1.02.1 libedit2 libelfg0 libexpat1 libfribidi0 libfuse2 libgc1c2 libgcc1 libgcrypt11 libgdbm3 libglib2.0-0 libgnutls13 libgomp1 libgpg-error0 libgpmg1
libhtml-parser-perl libhtml-tagset-perl libhtml-tree-perl libidn11 libisc35 libisccc30 libisccfg30 libiw29 libkeyutils1 libkrb53 libldap-2.4-2 liblist-moreutils-perl liblocale-gettext-perl
liblwres30 liblzo2-2 libmagic1 libmysqlclient15off libncurses5 libncursesw5 libneon27 libnet-daemon-perl libnewt0.52 libntfs-3g23 libopencdk10 libpam-modules libpam0g libparted1.7-1 libpcap0.8
libpcre3 libplrpc-perl libpopt0 libpq5 libreadline5 libreadline6 librpc-xml-perl libsasl2-2 libsasl2-modules libselinux1 libsepol1 libsigc++-2.0-0c2a libslang2 libsqlite3-0 libss2 libssl0.9.8
libstdc++6 libstdc++6-4.2-dev libsvn1 libsysfs2 libtasn1-3 libterm-readkey-perl libtext-charwidth-perl libtext-iconv-perl libtext-wrapi18n-perl liburi-perl libusb-0.1-4 libuuid1 libvolume-id0
libwrap0 libwww-perl libx11-6 libx11-data libxau6 libxcb-xlib0 libxcb1 libxdmcp6 libxext6 libxml-parser-perl libxml2 libxmuu1 linux-image-2.6.24-23-server linux-image-server linux-server
linux-ubuntu-modules-2.6.24-23-server locales locales-all login logrotate lsb-base lsb-release lshw lsof ltrace lvm2 lzma make makedev man-db mawk menu mii-diag mktemp mlocate module-init-tools
mount mtr-tiny mysql-client-5.0 mysql-server mysql-server-5.0 nano ncurses-base ncurses-bin net-tools netbase netcat netcat-traditional ntfs-3g ntp ntpdate openssh-client openssh-server parted
passwd pciutils pcmciautils perl perl-base perl-modules popularity-contest ppp pppconfig pppoeconf procps psmisc python python-apt python-central python-cxx python-cxx-dev python-dev
python-gdbm python-gnupginterface python-minimal python-mysqldb python-pkg-resources python-pycurl python-setuptools python-simplejson python-support python2.5 python2.5-dev python2.5-minimal
reiserfsprogs rsync screen sed sshfs startup-tasks strace subversion sudo sysklogd system-services sysvutils tar tasksel tasksel-data tcpd tcpdump telnet time tzdata ubuntu-keyring
ubuntu-minimal ubuntu-standard ucf udev ufw update-inetd update-manager-core upstart upstart-compat-sysv upstart-logd usbutils util-linux util-linux-locales uuid-runtime valgrind vim vim-common
vim-tiny w3m wget whiptail wireless-tools wpasupplicant x11-common xauth zlib1g
The following packages will be upgraded:
libdns35
WARNING: The following essential packages will be removed.
This should NOT be done unless you know exactly what you are doing!
apt libc6 (due to apt) libgcc1 (due to apt) libstdc++6 (due to apt) base-files base-passwd (due to base-files) libpam-modules (due to base-files) bash debianutils (due to bash) libncurses5 (due
to bash) bsdutils coreutils libacl1 (due to coreutils) libselinux1 (due to coreutils) dash mktemp (due to debianutils) diff dpkg lzma (due to dpkg) e2fsprogs e2fslibs (due to e2fsprogs)
libblkid1 (due to e2fsprogs) libcomerr2 (due to e2fsprogs) libss2 (due to e2fsprogs) libuuid1 (due to e2fsprogs) findutils grep gzip hostname login libpam0g (due to login) mount ncurses-base
ncurses-bin perl-base python-minimal python2.5-minimal (due to python-minimal) sed sysvutils libsepol1 (due to sysvutils) tar util-linux lsb-base (due to util-linux) tzdata (due to util-linux)
libslang2 (due to util-linux) zlib1g (due to util-linux)
1 upgraded, 0 newly installed, 316 to remove and 4 not upgraded.
4 not fully installed or removed.
Need to get 11.3kB of archives.
After this operation, 712MB disk space will be freed.
You are about to do something potentially harmful.
To continue type in the phrase 'Yes, do as I say!'
?]
显然,我没有输入“是的,按我说的做!”。好像真的搞砸了……知道如何解决吗?
最佳答案
我可以肯定,在带有 GCC 4.1.2 的 RHEL 5 上,代码工作正常,无论是 32 位还是 64 位(AMD x86/64 架构)。
您(可能)发现了一个错误。
也许您应该升级到 GCC 4.5.2(在过去 24 小时左右发布 - 截至 2010 年 12 月 19 日)。或者您可能需要升级 C 库,但这更有可能是编译器问题而不是库问题。
关于c - memcmp 中的意外段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4485882/
我想做的是让 JTextPane 在 JPanel 中占用尽可能多的空间。对于我使用的 UpdateInfoPanel: public class UpdateInfoPanel extends JP
我在 JPanel 中有一个 JTextArea,我想将其与 JScrollPane 一起使用。我正在使用 GridBagLayout。当我运行它时,框架似乎为 JScrollPane 腾出了空间,但
我想在 xcode 中实现以下功能。 我有一个 View Controller 。在这个 UIViewController 中,我有一个 UITabBar。它们下面是一个 UIView。将 UITab
有谁知道Firebird 2.5有没有类似于SQL中“STUFF”函数的功能? 我有一个包含父用户记录的表,另一个表包含与父相关的子用户记录。我希望能够提取用户拥有的“ROLES”的逗号分隔字符串,而
我想使用 JSON 作为 mirth channel 的输入和输出,例如详细信息保存在数据库中或创建 HL7 消息。 简而言之,输入为 JSON 解析它并输出为任何格式。 最佳答案 var objec
通常我会使用 R 并执行 merge.by,但这个文件似乎太大了,部门中的任何一台计算机都无法处理它! (任何从事遗传学工作的人的附加信息)本质上,插补似乎删除了 snp ID 的 rs 数字,我只剩
我有一个以前可能被问过的问题,但我很难找到正确的描述。我希望有人能帮助我。 在下面的代码中,我设置了varprice,我想添加javascript变量accu_id以通过rails在我的数据库中查找记
我有一个简单的 SVG 文件,在 Firefox 中可以正常查看 - 它的一些包装文本使用 foreignObject 包含一些 HTML - 文本包装在 div 中:
所以我正在为学校编写一个 Ruby 程序,如果某个值是 1 或 3,则将 bool 值更改为 true,如果是 0 或 2,则更改为 false。由于我有 Java 背景,所以我认为这段代码应该有效:
我做了什么: 我在这些账户之间创建了 VPC 对等连接 互联网网关也连接到每个 VPC 还配置了路由表(以允许来自双方的流量) 情况1: 当这两个 VPC 在同一个账户中时,我成功测试了从另一个 La
我有一个名为 contacts 的表: user_id contact_id 10294 10295 10294 10293 10293 10294 102
我正在使用 Magento 中的新模板。为避免重复代码,我想为每个产品预览使用相同的子模板。 特别是我做了这样一个展示: $products = Mage::getModel('catalog/pro
“for”是否总是检查协议(protocol)中定义的每个函数中第一个参数的类型? 编辑(改写): 当协议(protocol)方法只有一个参数时,根据该单个参数的类型(直接或任意)找到实现。当协议(p
我想从我的 PHP 代码中调用 JavaScript 函数。我通过使用以下方法实现了这一点: echo ' drawChart($id); '; 这工作正常,但我想从我的 PHP 代码中获取数据,我使
这个问题已经有答案了: Event binding on dynamically created elements? (23 个回答) 已关闭 5 年前。 我有一个动态表单,我想在其中附加一些其他 h
我正在尝试找到一种解决方案,以在 componentDidMount 中的映射项上使用 setState。 我正在使用 GraphQL连同 Gatsby返回许多 data 项目,但要求在特定的 pat
我在 ScrollView 中有一个 View 。只要用户按住该 View ,我想每 80 毫秒调用一次方法。这是我已经实现的: final Runnable vibrate = new Runnab
我用 jni 开发了一个 android 应用程序。我在 GetStringUTFChars 的 dvmDecodeIndirectRef 中得到了一个 dvmabort。我只中止了一次。 为什么会这
当我到达我的 Activity 时,我调用 FragmentPagerAdapter 来处理我的不同选项卡。在我的一个选项卡中,我想显示一个 RecyclerView,但他从未出现过,有了断点,我看到
当我按下 Activity 中的按钮时,会弹出一个 DialogFragment。在对话框 fragment 中,有一个看起来像普通 ListView 的 RecyclerView。 我想要的行为是当
我是一名优秀的程序员,十分优秀!