Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8322903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:32:27+00:00 2026-06-08T23:32:27+00:00

When I run this code to load a jpeg file I get a crash

  • 0

When I run this code to load a jpeg file I get a crash in jpeg_read_scanlines
I’m using windows 7 64 bit with VC++ 2010

The image I’m loading is a 100×75 jpg image.

If you need any more details just ask

The crash message is:
Unhandled exception at 0x012db29e in LibTest.exe: 0xC0000005: Access violation writing location 0xcdcdcdcd.

void JPG_Load (const char *path, image_t *img) 
{
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
int infile;
JSAMPARRAY buffer;  
int row_stride;     
unsigned char *out;

infile = fopen(path,"rb");
if (infile == 0) {
    memset (img, 0, sizeof(image_t));
    return;
}

cinfo.err = jpeg_std_error(&jerr);

jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, (FILE *)infile);
jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cinfo);
row_stride = cinfo.output_width * cinfo.output_components;
out = malloc(cinfo.output_width*cinfo.output_height*cinfo.output_components);

img->pixels = out;
img->width = cinfo.output_width;
img->height = cinfo.output_height;
img->bytesPerPixel = cinfo.out_color_components;

while (cinfo.output_scanline < cinfo.output_height) {
    buffer = (JSAMPARRAY)out+(row_stride*cinfo.output_scanline);
    jpeg_read_scanlines(&cinfo, buffer, 1);
}

jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);

fclose(infile);
}

image_t is defined as:

typedef struct {
int width;
int height;
int bytesPerPixel;
byte *pixels;
} image_t;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:32:29+00:00Added an answer on June 8, 2026 at 11:32 pm

    Don’t do this.

    buffer = (JSAMPARRAY)out+(row_stride*cinfo.output_scanline); // WRONG
    

    You are casting to JSAMPARRAY, which is basically void **. The result is garbage, since that’s not the kind of data you have: you have an array of bytes.

    The jpeg_read_scanlines function, if you look at the documentation, does not take a pointer to your buffer. It takes a pointer to an array of scanlines, and each scanline is a pointer to row data.

    while (cinfo.output_scanline < cinfo.output_height) {
        unsigned char *rowp[1];
        rowp[0] = (unsigned char *) out + row_stride * cinfo.output_scanline;
        jpeg_read_scanlines(&cinfo, rowp, 1);
    }
    

    Recommendation: Adding a cast to fix a compiler error only works if you know the cast is correct. Don’t cast to any type unless you know what the type is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On document ready I run this code: jQuery(document).ready(function(){ jQuery('#button').click(function() { jQuery('#contact_form').load(/Users/mge/Downloads/jquery-ajax-1/readme.txt); return false; });
When I run this code to call the Google API, all I get is
I can run this code in Android app (using PhoneGap adn jQuery Mobile) but
Hello i`ve got a problem: when i run this code i get this: on
How i can Decrease the report file Loading Time? I Use this Code to
If I run this Code: function sendRequest() { var req = new XMLHttpRequest(); req.open(GET,
With this code I am trying to load a file with data into an
I run this code here <html> <script type=text/javascript src=lib/jquery-ui-1.8.21.custom.min.js></script> <script src=http://127.0.0.1:5984/_utils/script/jquery.couch.js></script> <!--<script type=text/javascript src=lib/jquery-1.7.2.js></script>-->
I run this code: - (void)unitButtonButtonTapped:(id)sender { [_label setString:@Last button: Unembossed square]; MilitaryUnits *target
Why this code don't work,when i want run this code vwd 2008 express show

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.