在某些情况下,fwrite写入额外数据(比请求的字节多).简短演示的输出是最简单的解释方式.该演示尝试创建两个2048字节的文件,并在每次fwrite调用后检查偏移量,以确定写入的字节数.第一个fwrite调用写入两个额外的字节:
len: 2048
current offset = 0
wrote 1024 bytes
current offset = 1026
EXITING:
offset % BLOCKSIZE = 2
len: 2048
current offset = 0
wrote 1024 bytes
current offset = 1024
wrote 1024 bytes
SUCCESS
Run Code Online (Sandbox Code Playgroud)
当编译为ELF(unix二进制文件)时,程序成功运行(写入2048字节到两个文件),但在编译为PE(Windows二进制文件/可执行文件)时失败(如上所示).我尝试过编译和测试:
Ubuntu 14.04 and gcc 4.8.2 - SUCCESS
WINE 1.6.2 and mingw 4.8.2 - FAIL
Windows 7 and mingw 4.8.2 - FAIL
Windows 7 and Visual Studio 2013 - FAIL
Run Code Online (Sandbox Code Playgroud)
传递的缓冲区中的实际数据fwrite会影响写入的额外字节数,但实际上每次都会发生这种情况(除非您写入NULL字节).
main.c中:
#include <stdio.h>
#include …Run Code Online (Sandbox Code Playgroud) 我正在开发一个FUSE驱动程序,当我将它作为守护进程运行时(没有-f或-d标志),通过libcurl发出的所有https请求都会失败.我能够通过发出https请求,分叉和返回父进程,然后从新进程发出第二个请求来重现错误.如果我删除了fork呼叫或发出http请求,则没有错误.
我现在正在制作官方错误报告,但是有谁知道我怎么能让它发挥作用?
这是我的代码和(logfile)输出:
注意:如果您运行我的程序,请管道到/ dev/null,因为libcurl默认将接收到的缓冲区发送到stdout.
#include <curl/curl.h>
#include <string>
#include <unistd.h>
#include <iostream>
using namespace std;
void log(string str)
{ //TODO: remove
static const char logfile[] = "/home/austin/megalog";
FILE *f = fopen(logfile, "a");
fwrite(str.data(), str.size(), 1, f);
fclose(f);
cout << str;
}
int main(int argc, char *argv[])
{
string url = "https://www.google.com/";
char errBuf[1024];
CURLcode err;
curl_global_init(CURL_GLOBAL_DEFAULT);
CURL *handle = curl_easy_init();
curl_easy_setopt(handle, CURLOPT_URL, url.c_str());
curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, errBuf);
if ((err = curl_easy_perform(handle)))
{
log("first request failed\n");
return 1;
} …Run Code Online (Sandbox Code Playgroud) 我知道应该避免使用eval()和exec(),但在这种情况下它似乎是最好的选择:我从wxPython中的复选框和文本框中获取值并将它们放入我的配置类中.这是我使用eval()的方式:
config = wx.Config()
checkBoxes = ['option_1', 'option_2']
for key in checkBoxes:
config.Write(key, str(eval('self.m_checkBox_'+key+'.GetValue()'))
Run Code Online (Sandbox Code Playgroud)
没有任何安全问题,因为没有任何用户输入到eval,对我来说似乎很清楚.有一个更好的方法吗?