h4xxel / html Goto Github PK
View Code? Open in Web Editor NEWa simple html parser lacking a better name
License: MIT License
a simple html parser lacking a better name
License: MIT License
Dear Friend
thank you for your grate effort. I wrote the "main()" into thread and I created that thread 1000 times.
it gets segmentation fault randomly.
the problem is html_parse_stream() function. But because the seg fault is random I can not follow the problem. would you please help me.
My compiler:
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin15.3.0
Thread model: posix
When i run program, return output is this:
Segmentation fault: 11
My solution is to change two lines into attrib.c C file ( attrib_append() function ):
if ((attrib) != NULL) {
attrib = (struct HtmlAttrib)malloc(sizeof(HtmlAttrib));
Great job,
Emilio
My solution works with small BUFFERSIZE value... but now i lose lastest bytes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "html.h"
#define BUFFSIZE 2
int main(int argc, char **argv) {
//TODO: dynamic buffer handling to never overflow
FILE *f;
HtmlDocument *doc;
HtmlParseState *parse_state;
char *buf = NULL;
buf = (char*) realloc (buf, (BUFFSIZE+1) * sizeof(char));
buf[BUFFSIZE] = 0;
const char *token = buf;
if(argc != 2) {
fprintf(stderr, "usage: html <file.html>\n");
return 1;
}
size_t len = 0;
size_t buffsize = BUFFSIZE;
parse_state = html_parse_begin();
if(!(f = fopen(argv[1], "r"))) {
fprintf(stderr, "error: cannot open file %s\n", argv[1]);
return 1;
}
int gain=0;
int aftergain=0;
int add=0;
while(!feof(f)) {
if (buffsize==0) {
gain++;
add=1;
buf = (char*) realloc (buf, (gain+BUFFSIZE + 1) * sizeof(char));
buf[gain+BUFFSIZE] = 0;
} else {
add = 0;
}
len = fread(buf+(BUFFSIZE+aftergain-buffsize), 1, add+buffsize, f);
token = html_parse_stream(parse_state, buf + (BUFFSIZE+aftergain-buffsize), buf, len);
buffsize = (token - buf);
memmove(buf, token, BUFFSIZE+gain-buffsize);
aftergain=gain;
}
doc = html_parse_end(parse_state);
fclose(f);
html_print_dom(doc);
html_free_document(doc);
free(buf);
return 0;
}
Check this pls
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.