- fwrite(jpegtables, 1, jpegtablessize-2, fi); //don't write end tag (ff,d8)
- fwrite(&tag->data[2+2], tag->len-2-2, 1, fi); //don't write start tag (ff,d9)
+ if(jpegtablessize>=2) {
+ fwrite(jpegtables, 1, jpegtablessize-2, fi); //don't write end tag (ff,d8)
+ fwrite(&tag->data[2+2], tag->len-2-2, 1, fi); //don't write start tag (ff,d9)
+ } else {
+ fwrite(tag->data+2, tag->len-2, 1, fi);
+ }