- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
大家好,我基本上是在尝试使用 zlib 库,但是当我尝试膨胀一个 self 收缩的文件时遇到了麻烦,尽管当我膨胀其他 zlib´d 文件时它工作正常。
压缩代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef unsigned char BYTE;
typedef unsigned int UINT;
#include "zlib.h"
#define HEADERSIZE (1024)
#define CHUNKSIZE 4096
#define SWAPINT(x) (((x)&0xFF) << 24)|(((x)&0xFF00) << 8) | (((x)&0xFF0000) >> 8) | (((x)&0xFF000000) >> 24)
#define DEFLATESIZE 65536
const char *mz_error(int err)
{
static struct { int m_err; const char *m_pDesc; } s_error_descs[] =
{
{ Z_OK, "" }, { Z_STREAM_END, "stream end" }, { Z_NEED_DICT, "need dictionary" }, { Z_ERRNO, "file error" }, { Z_STREAM_ERROR, "stream error" },
{ Z_DATA_ERROR, "data error" }, { Z_MEM_ERROR, "out of memory" }, { Z_BUF_ERROR, "buf error" }, { Z_VERSION_ERROR, "version error" }
};
UINT i; for (i = 0; i < sizeof(s_error_descs) / sizeof(s_error_descs[0]); ++i) if (s_error_descs[i].m_err == err) return s_error_descs[i].m_pDesc;
return NULL;
}
char* myinflate(char* buffer, int bufsize, int* inflatedSize)
{
BYTE tmpinf[DEFLATESIZE];
char* inflated=(char*)malloc(DEFLATESIZE);
int ret,have;
z_stream strm;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = bufsize;
strm.next_in = (Bytef*)buffer;
strm.avail_out = sizeof(tmpinf);
strm.next_out = tmpinf;
ret = inflateInit(&strm);
printf("%s",mz_error(ret));
ret = inflate(&strm, Z_FINISH);
printf("%s",mz_error(ret));
if(ret == Z_DATA_ERROR)
printf(strm.msg);
inflateEnd(&strm);
have = strm.total_out;
printf("%d\n",have);
memcpy(inflated,tmpinf,have);
*inflatedSize = have;
return inflated;
}
char* mydeflate(char* buffer, int bufsize, int* deflatedSize)
{
BYTE tmpdef[CHUNKSIZE*4];
char* deflated=(char*)malloc(DEFLATESIZE);
int have,ret;
z_stream strm;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = bufsize;
strm.next_in = (Bytef*)buffer;
strm.avail_out = sizeof(tmpdef);
strm.next_out = tmpdef;
ret = deflateInit(&strm,Z_DEFAULT_COMPRESSION);
printf("%s",mz_error(ret));
ret = deflate(&strm, Z_FINISH);
printf("%s",mz_error(ret));
ret = deflateEnd(&strm);
printf("%s",mz_error(ret));
have = strm.total_out;
printf("%d\n",have);
memcpy(deflated,tmpdef,have);
*deflatedSize = have;
return deflated;
}
int main()
{
FILE* fptr = fopen("test.in","rb");
fseek (fptr, 0, SEEK_END);
int size = ftell(fptr);
fseek (fptr, 0, SEEK_SET);
char* buffer = (char*)malloc(size);
fread(buffer,1,size,fptr);
int infsize,defsize;
char* buf = myinflate(buffer,size,&infsize);
FILE* out = fopen("testinf.hex","wb");
fwrite(buf,1,infsize,out);
fclose(out);
char* buf2 = mydeflate(buf,infsize,&defsize);
out = fopen("testdef.hex","wb");
fwrite(buf2,1,defsize,out);
fclose(out);
int buf3size;
char* buf3 = myinflate(buf2,defsize,&buf3size);
out = fopen("testinfdef.hex","wb");
fwrite(buf3,1,buf3size,out);
}
http://www.filehosting.org/file/details/364574/eEyzAbMuCp93MmGk/test.in
最佳答案
您没有检查任何 返回码。你怎么可能期望知道发生了什么事? 检查所有可能返回错误的函数的返回码!
可能根本没有提供足够的空间用于压缩和/或解压缩。 inflate()
和 compress()
的返回码表明是否是这种情况。
顺便说一下,您 malloc()
inflated
两次,覆盖了第一次导致大量内存泄漏。
您还愉快地将一个 int 指针转换为一个无符号长指针。如果它们的长度不同,那么您就会遇到问题。
关于c++ - Zlib 膨胀和收缩错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11803606/
我需要使用view.getWidth(),但我不能,因为我还没有膨胀 View 。在使用 view.getWidth() 之前如何膨胀 View ? MainActivity 类: p
这个问题很难尝试和表述,但我会尽力而为。 基本上,我有一个应用程序,我想将代码拆分得更多。为了尝试解释这一点,我将举一个我的屏幕示例。 在我的主屏幕上,我有一个标题、用户详细信息、余额、下一个账单详细
我有一个 TableLayout,我在其中动态添加行,一开始是空的,我想在用户单击它时在该行中加载一个 xml。 我已经给行赋值了OnClick方法,但是不知道在onclick方法中进入时如何加载xm
我使用的是 C++ 中的 libcurl 库,这是一个相当大的库(.lib 文件大约 2MB),项目是用 CURL_STATICLIB 编译的 至于现在我只有一个 .cpp 文件,其中包含 heade
背景: 我正在努力使一堆 PNG 尽可能小。我正在使用诸如 PngOut、PngCrush 和 OptiPng 之类的工具。 问题: 我遇到了一个大小为 1434 KB 但只有 230 x 230 像
我一直在努力找出我的应用程序使用的内存不断增长的原因,直到在 heroku 上的生产中它失败并下降。 经过一些相当广泛的研究,使用 Top 观察 RSIZE 在本地增长并使用 Oink 尝试查明我只是
我有一个使用 C++ 版本的 zlibs deflate 压缩的数据 ArrayBuffer(使用默认值)。由于没有服务器,我现在需要在客户端中增加这些数据。我已经使用 C++ 中的默认 inflat
我的代码有问题: @Override public View getView(int position, View convertView, ViewGroup parent) {
我有一个 fragment ,我像下面一样对其进行膨胀,但它给出了运行时错误: public View onCreateView(LayoutInflater inflater, ViewGroup
我正在学习 Fragment,并且我是通过在 Fragment 中使用 FB Login 来学习的。但我不断收到异常 Error inflateing class com.facebook.login
第一种方法: LinearLayout parent = ...; View child = LayoutInflator.inflate(context, parent, true); 第二种方法:
我刚刚完成了一个站点构建,在该站点构建中,我们必须将文件提供给第 3 方以与他们的系统集成。构建必须是独立的,因为会有多方部署它们,能力水平各不相同。 我遇到的问题是,在下载我的 Javascript
我正在寻找一种方法来“扩充”Android XML 布局,这在编译时是未知的。我已经搜索了几个小时,总能找到答案,这是不可能的,因为 LayoutInflater 不能使用简单的 XML 文件。好的,
我有一个从 Faragment 扩展而来的类,叫做 Agenda。它的布局有一个 listView,但是当这个类返回到主 Activity 时,我得到了一个错误。这是错误和代码: > 03-11 13
我的应用程序一启动就崩溃了。我收到以下错误: android.view.InflateException: Binary XML file line #34: Error inflating clas
我想膨胀 R.id.catText,但如果我自己膨胀它,它永远不会显示。如果我inflate R.id.assets(容器),那么两个元素都会正常显示。我只是不想要容器。如何在不膨胀 R.id.ass
我尝试创建自定义 ViewGroup 类,但是当我使用方法 findViewById() 时它返回 null,但展开 View 是可以的。 代码是: public class HorizontalLi
我正在尝试创建一个在屏幕上滑动的 textView,但它会产生错误,但我不知道为什么。这是我的 xml: 还有我的 Activity 课: package com.exampl
我正在构建一个应用程序,我在其中使用了 glomadrain 的动画切换按钮。完成编码后出现以下错误: at com.android.internal.os.ZygoteInit.main(Zygot
我只是想按照 android dev 上的示例代码来膨胀 Activity 中的 fragment 。我有一个更复杂的项目正在工作,但我遇到了与这里的简单项目相同的错误。谁能指出我正确的方向? 扩展
我是一名优秀的程序员,十分优秀!