Upon further looking it appears that the problem was with a windows function to open the .cl file.
_sopen_s(&fd, filename, _O_RDONLY, _SH_DENYRW, _S_IREAD) ;
Upon changing it to:
_sopen_s(&fd, filename, _O_RDONLY | O_BINARY, _SH_DENYRW, _S_IREAD) ;
Tada! Problem solved.
Here's where it was screwing up without using the O_BINARY flag:
outputImage[idx] = sum.x ;
}
}
lumn ;
outputImage[idx] = sum.x ;
}
}
And fixed it looked as it should:
outputImage[idx] = sum.x ;
}
}
Why was this happening? No idea.
EDIT: After reading the comments by sharpneli and jprice I decided to do some more digging to figure out what the exact issue was.
The O_BINARY flag isn't actually need as I traced the root cause to a discrepancy between:
*filesize = (int64_t *)_filelengthi64(fd)
and
bytesRead = _read( fileDescriptor, *fileContents, (UINT)filesize ) ;
Filesize was 765 whereas bytesRead was 733.
A bit further down the original line wherein the problem ultimately lay was:
//make sure string is null terminated
(*fileContents)[(int)filesize -1] = '\0' ;
and upon changing to:
(*fileContents)[(int)bytesRead-1] = '\0' ;
Voila.