Commits

Ondřej Surý committed 73cab5d

Use gdtest helper functions in jpeg/jpeg_read.c

  • Participants
  • Parent commits be262a9

Comments (0)

Files changed (1)

File tests/jpeg/jpeg_read.c

 
 int main()
 {
-	int error;
 	gdImagePtr im;
 	FILE *fp;
 	char path[1024];
 
-	sprintf(path, "%s/jpeg/conv_test.jpeg", GDTEST_TOP_DIR);
+	snprintf(path, sizeof(path), "%s/jpeg/conv_test.jpeg", GDTEST_TOP_DIR);
 	fp = fopen(path, "rb");
 	if (!fp) {
-		printf("failed, cannot open file\n");
+		gdTestErrorMsg("failed, cannot open file: %s\n", path);
 		return 1;
 	}
 
 	im = gdImageCreateFromJpeg(fp);
 	fclose(fp);
 
-	sprintf(path, "%s/jpeg/conv_test_exp.png", GDTEST_TOP_DIR);
+	if (im == NULL) {
+		gdTestErrorMsg("gdImageCreateFromJpeg failed.\n");
+		return 1;
+	}
+	snprintf(path, sizeof(path), "%s/jpeg/conv_test_exp.png", GDTEST_TOP_DIR);
 	if (!gdAssertImageEqualsToFile(path, im)) {
-		error = 1;
-	} else {
-		if (im) {
-			gdImageDestroy(im);
-			error = 0;
-		} else {
-			error = 1;
-		}
+		gdTestErrorMsg("gdAssertImageEqualsToFile failed.\n");
+		gdImageDestroy(im);
+		return 1;
 	}
-	return error;
+
+	return 0;
 }