[英]“Syscall param open(mode) contains uninitialised byte(s)” in open sys call
fd = open(pathname, O_WRONLY | O_LARGEFILE | O_APPEND | O_CREAT);
When running my tests I encounter a valgrind error: 运行我的测试时遇到valgrind错误:
==14280== Syscall param open(mode) contains uninitialised byte(s)
==14280== at 0x4111084: open64 (open64.c:42)
And the return value of open
is -2
并且
open
的返回值是-2
Errno is set to 13 (Permission denied)
Errno被设置为
13 (Permission denied)
The pathname
buffer contains: pathname
缓冲区包含:
0x68
0x72
0x32
0x2E
0x66
0x61
0x0
Info about my system: 关于我的系统的信息:
$ ls -la
drwxr-xr-x 7 rzetterberg zed 4096 Jul 4 13:56 .
$ id
uid=1000(rzetterberg) gid=1000(rzetterberg) groups=1000(rzetterberg), ... etc
$ sudo file -Ls /dev/sda1
/dev/sda1: sticky Linux rev 1.0 ext3 filesystem data, UUID=XXXX (needs journal recovery) (large files)
$ uname -a
Linux xxxx 3.2.0-4-686-pae #1 SMP Debian 3.2.46-1 i686 GNU/Linux
Headers included: 标题包括:
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
I don't understand how mode
can have unitialised bytes and why I'm getting a Permission denied
. 我不明白
mode
如何具有单位化字节以及为什么我的Permission denied
。 It seems very strange to me! 这对我来说似乎很奇怪!
If you supply the O_CREAT
flag to open()
, you must supply a third argument. 如果为
open()
提供O_CREAT
标志,则必须提供第三个参数。 This is an integer which represents the permissions to apply to the created file (modified by the current umask
). 这是一个整数,表示应用于创建文件的权限(由当前
umask
修改)。
When you call open
with O_CREAT
you need a third argument to the system call. 当您使用
O_CREAT
调用open
,您需要系统调用的第三个参数。 That parameter is called mode
. 该参数称为
mode
。 Valgrind is reporting uninitialized bytes because it doesn't know that you didn't specify the argument, but it sees that whatever happened to be on the stack isn't what it expects. Valgrind报告未初始化的字节,因为它不知道你没有指定参数,但是它发现堆栈上发生的任何事情并不是它所期望的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.