Oleg Oshmyan avatar Oleg Oshmyan committed 236c885

audit formatted input/output of integers

* Use no length modifiers when printing [u]int(8|16)_t, [[un]signed]
char and [unsigned] short int due to integral promotions.
* Cast int(8|16)_t, [signed] char and short int to unsigned
types before promotion when they are printed with unsigned
conversion specifiers to ensure that promotion does not produce
negative values that are then printed as huge positive numbers.
* Use strtoul to read [[un]signed] char and [u]int8_t
because Windows does not support the `hh` length modifier.
* Use <inttypes.h> format macros for <stdint.h> types in all other cases.
* Make sure to use PRI macros for printing and SCN macros for scanning.
* Clean up a few lines along the way.

Comments (0)

Files changed (8)

src/AtomicParsley.h

 #endif
 
 #ifndef PRIu64
-# define PRIu64 "llu"
+# ifdef _WIN32
+#  define PRIu64 "I64u"
+# else
+#  define PRIu64 "llu"
+# endif
 #endif
-#ifndef PRIu16
-# define PRIu16 "hu"
+#ifndef PRIu32
+# define PRIu32 "u"
 #endif
-#ifndef PRIu8
-# define PRIu8 "hhu"
+#ifndef PRIx32
+# define PRIx32 "x"
+#endif
+#ifndef SCNu64
+# ifdef _WIN32
+#  define SCNu64 "I64u"
+# else
+#  define SCNu64 "llu"
+# endif
 #endif
 #ifndef SCNu32
-# define SCNu32 "lu"
+# define SCNu32 "u"
 #endif
 #ifndef SCNu16
-# define SCNu16 "u"
+# define SCNu16 "hu"
 #endif
 
 #ifndef MIN
 
 	if (track_info->type_of_track & VIDEO_TRACK &&
 			( ( track_info->max_bitrate > 0 && track_info->ObjectTypeIndication == 0x20) || track_info->avc_version == 1 || track_info->protected_codec != 0) ) {
-		fprintf(stdout, "  %ux%u  (%u macroblocks)\n", track_info->video_width, track_info->video_height, track_info->macroblocks);
+		fprintf(stdout, "  %ux%u  (%" PRIu32 " macroblocks)\n", track_info->video_width, track_info->video_height, track_info->macroblocks);
 	} else if (track_info->type_of_track & VIDEO_TRACK) {
 		fprintf(stdout, "\n");
 	}
 	if (optional_output & SHOW_TRACK_INFO) {
 		APar_TrackLevelInfo(&track, NULL); //With track_num set to 0, it will return the total trak atom into total_tracks here.
 
-		fprintf(stdout, "Low-level details. Total tracks: %u \n", track.total_tracks);
+		fprintf(stdout, "Low-level details. Total tracks: %u\n", track.total_tracks);
 		fprintf(stdout, "Trk  Type  Handler                    Kind  Lang  Bytes\n");
 
 		if (track.total_tracks > 0) {
 				}
 
 				//codec, language
-				fprintf(stdout, "  %s  %s   %" PRIu64 "", uint32tochar4(track_info.track_codec, uint32_buffer), track_info.unpacked_lang, track_info.sample_aggregate);
+				fprintf(stdout, "  %s  %s   %" PRIu64, uint32tochar4(track_info.track_codec, uint32_buffer), track_info.unpacked_lang, track_info.sample_aggregate);
 
 				if (track_info.encoder_name[0] != 0 && track_info.contains_esds) {
 					purge_extraneous_characters(track_info.encoder_name);
 		}
 
 		uint32_t minor_version = APar_read32(buffer, a_file, 12+file_type_offset);
-		fprintf(stdout, "  -  version %u\n", minor_version);
+		fprintf(stdout, "  -  version %" PRIu32 "\n", minor_version);
 
 		fprintf(stdout, " Compatible Brands:");
 		for (uint64_t i = 16+file_type_offset; i < atom_length; i+=4) {
 
 void APar_LimitBufferRange(uint32_t max_allowed, uint32_t target_amount) {
 	if (target_amount > max_allowed) {
-		fprintf(stderr, "AtomicParsley error: insufficient memory to process ID3 tags (%u>%u). Exiting.\n", target_amount, max_allowed);
+		fprintf(stderr, "AtomicParsley error: insufficient memory to process ID3 tags (%" PRIu32 ">%" PRIu32 "). Exiting.\n", target_amount, max_allowed);
 		exit( target_amount - max_allowed );
 	}
 	return;
 			break;
 		}
 	}
-	//fprintf(stdout, "%u, %s, %s\n", bytes_used, buffer, (thisFrame->ID3v2_Frame_Fields+fieldNum)->field_string);
+	//fprintf(stdout, "%" PRIu32 ", %s, %s\n", bytes_used, buffer, (thisFrame->ID3v2_Frame_Fields+fieldNum)->field_string);
 	return bytes_used;
 }
 
 	
 	if (ID3v2_TestTagFlag(id32_atom->ID32_TagInfo->ID3v2Tag_Flags, ID32_TAGFLAG_UNSYNCRONIZATION)) {
 		//uint32_t newtagsize = ID3v2_desynchronize(id32_fulltag, id32_atom->ID32_TagInfo->ID3v2Tag_Length);
-		//fprintf(stdout, "New tag size is %u\n", newtagsize);
+		//fprintf(stdout, "New tag size is %" PRIu32 "\n", newtagsize);
 		//WriteZlibData(id32_fulltag, newtagsize);
 		//exit(0);
 		fprintf(stdout, "AtomicParsley error: an ID3 tag with the unsynchronized flag set which is not supported. Skipping.\n");
 				if (this_field->field_string != NULL) {
 					memcpy(dest_buffer + *frame_length, this_field->field_string, this_field->field_length);
 					*frame_length += this_field->field_length;
-					//fprintf(stdout, "Field idx %u(%d) is now %u bytes long (+%u)\n", fld_idx, this_field->ID3v2_Field_Type, *frame_length, this_field->field_length);
+					//fprintf(stdout, "Field idx %u(%d) is now %" PRIu32 " bytes long (+%" PRIu32 ")\n", fld_idx, this_field->ID3v2_Field_Type, *frame_length, this_field->field_length);
 				}
 				break;
 			}
 						*frame_length += this_field->field_length;
 					}
 				}
-				//fprintf(stdout, "Field idx %u(%d) is now %u bytes long\n", fld_idx, this_field->ID3v2_Field_Type, *frame_length);
+				//fprintf(stdout, "Field idx %u(%d) is now %" PRIu32 " bytes long\n", fld_idx, this_field->ID3v2_Field_Type, *frame_length);
 				break;
 			}
 			
 					*frame_length += this_field->field_length;
 
 				}
-				//fprintf(stdout, "Field idx %u(%d) is now %u bytes long\n", fld_idx, this_field->ID3v2_Field_Type, *frame_length);
+				//fprintf(stdout, "Field idx %u(%d) is now %" PRIu32 " bytes long\n", fld_idx, this_field->ID3v2_Field_Type, *frame_length);
 				break;
 			}
 			default : {
 	this_field->field_length = 0;
 	this_field->alloc_length = byte_allocation;
 	this_field->next_field = NULL;
-	//fprintf(stdout, "For %u field, %u bytes were allocated.\n", this_field->ID3v2_Field_Type, byte_allocation);
+	//fprintf(stdout, "For %u field, %" PRIu32 " bytes were allocated.\n", this_field->ID3v2_Field_Type, byte_allocation);
 	return;
 }
 
 		if (converted_bytes > 0) {
 			thisField->field_length += converted_bytes;
 			bytes_used = converted_bytes;
-			//fprintf(stdout, "string %s, %u=%u\n", thisField->field_string, thisField->field_length, bytes_used);
+			//fprintf(stdout, "string %s, %" PRIu32 "=%" PRIu32 "\n", thisField->field_string, thisField->field_length, bytes_used);
 		}
 		
 	} else if (str_encoding == TE_UTF16BE_NO_BOM) {
 					playcount = 1;
 				}
 			} else {
-				sscanf(frame_payload, "%" PRIu64 "", &playcount);
+				sscanf(frame_payload, "%" SCNu64, &playcount);
 			}
 			
 			if (playcount < 268435455) {
 				sizeof(popm_play_count_syncsafe));
 			
 			if (adjunct_payload->ratingArg != NULL) {
-				sscanf(adjunct_payload->ratingArg, "%hhu", &popm_rating);
+				popm_rating = strtoul(adjunct_payload->ratingArg, NULL, 10);
 			}
 			thisFrame->ID3v2_Frame_Length += APar_TextFieldDataPut(thisFrame->ID3v2_Frame_Fields, frame_payload, TE_LATIN1); //owner field
 			thisFrame->ID3v2_Frame_Length += APar_BinaryFieldPut(thisFrame->ID3v2_Frame_Fields+1, 0, (char*)&popm_rating, 1); //rating
 							popm_playcount = 1;
 						}
 					} else {
-						sscanf(adjunct_payload->dataArg, "%" PRIu64 "", &popm_playcount);
+						sscanf(adjunct_payload->dataArg, "%" SCNu64, &popm_playcount);
 					}
 				}
 			}
 			if (genre_idx != 0xFF) {
 				char genre_str_idx[2];
 				genre_str_idx[0] = 0; genre_str_idx[1] = 0; genre_str_idx[1] = 0;
-				sprintf(genre_str_idx, "%" PRIu8 "", genre_idx);
+				sprintf(genre_str_idx, "%u", genre_idx);
 				APar_FrameDataPut(targetFrame, genre_str_idx, adjunct_payloads, str_encoding);
 			} else {
 				APar_FrameDataPut(targetFrame, frame_payload, adjunct_payloads, str_encoding);
 
         if (strncmp(env_pad_prefs_ptr, "DEFAULT_PAD=", 12) == 0) {
             strsep(&env_pad_prefs_ptr,"=");
-            sscanf(env_pad_prefs_ptr, "%u", &pad_prefs.default_padding_size);
+            sscanf(env_pad_prefs_ptr, "%" SCNu32, &pad_prefs.default_padding_size);
         }
         if (strncmp(env_pad_prefs_ptr, "MIN_PAD=", 8) == 0) {
             strsep(&env_pad_prefs_ptr,"=");
-            sscanf(env_pad_prefs_ptr, "%u", &pad_prefs.minimum_required_padding_size);
+            sscanf(env_pad_prefs_ptr, "%" SCNu32, &pad_prefs.minimum_required_padding_size);
         }
         if (strncmp(env_pad_prefs_ptr, "MAX_PAD=", 8) == 0) {
             strsep(&env_pad_prefs_ptr,"=");
-            sscanf(env_pad_prefs_ptr, "%u", &pad_prefs.maximum_present_padding_size);
+            sscanf(env_pad_prefs_ptr, "%" SCNu32, &pad_prefs.maximum_present_padding_size);
         }
     }
-    //fprintf(stdout, "Def %u; Min %u; Max %u\n", pad_prefs.default_padding_size, pad_prefs.minimum_required_padding_size, pad_prefs.maximum_present_padding_size);
+    //fprintf(stdout, "Def %" PRIu32 "; Min %" PRIu32 "; Max %" PRIu32 "\n", pad_prefs.default_padding_size, pad_prefs.minimum_required_padding_size, pad_prefs.maximum_present_padding_size);
     return;
 }
 
             } else if ( strncmp(argv[optind + i], "track=", 6) == 0 ) {
                 char* track_index_str = argv[optind + i];
                 strsep(&track_index_str, "=");
-                sscanf(track_index_str, "%" PRIu8 "", &trk_idx);
+                trk_idx = strtoul(track_index_str, NULL, 10);
                 udta_container = SINGLE_TRACK_ATOM;
             } else if ( strcmp(argv[optind + i], "track") == 0 ) {
                 udta_container = ALL_TRACKS_ATOM;
             } else if ( strncmp(argv[optind + i], "track=", 6) == 0 ) {
                 char* track_index_str = argv[optind + i];
                 strsep(&track_index_str, "=");
-                sscanf(track_index_str, "%hhu", meta_container);
+                *meta_container = strtoul(track_index_str, NULL, 10);
             }
         }
 
                 if (strncmp(optarg, "value=", 6) == 0) {
                     char* stik_val_str_ptr = optarg;
                     strsep(&stik_val_str_ptr,"=");
-                    sscanf(stik_val_str_ptr, "%" PRIu8 "", &stik_value);
+                    stik_value = strtoul(stik_val_str_ptr, NULL, 10);
                 } else {
                     stiks* return_stik = MatchStikString(optarg);
                     if (return_stik != NULL) {
 
                 while (a_track < total_tracks) {
                     a_track++;
-                    sprintf(atom_path, "moov.trak[%" PRIu8 "].mdia.minf.stbl.stsd.avc1", a_track);
+                    sprintf(atom_path, "moov.trak[%u].mdia.minf.stbl.stsd.avc1", a_track);
                     video_desc_atom = APar_FindAtom(atom_path, false, VERSIONED_ATOM, 0, false);
 
                     if (video_desc_atom != NULL) {
                         uint16_t mb_t = APar_TestVideoDescription(video_desc_atom, APar_OpenFile(ISObasemediafile, "rb"));
                         if (mb_t > 0 && mb_t <= 1200) {
-                            sprintf(atom_path, "moov.trak[%" PRIu8 "].mdia.minf.stbl.stsd.avc1.uuid=", a_track);
+                            sprintf(atom_path, "moov.trak[%u].mdia.minf.stbl.stsd.avc1.uuid=", a_track);
                             uint8_t uuid_baselen = (uint8_t)strlen(atom_path);
                             APar_uuid_scanf(atom_path + uuid_baselen, "6b6840f2-5f24-4fc5-ba39-a51bcf0323f3");
                             APar_endian_uuid_bin_str_conversion(atom_path + uuid_baselen);
                     if ( strncmp(argv[optind + i], "trknum=", 7) == 0 ) {
                         char* track_num = argv[optind + i];
                         strsep(&track_num,"=");
-                        sscanf(track_num, "%" PRIu8 "", &tracknum);
+                        tracknum = strtoul(track_num, NULL, 10);
                     }
                     if (*argv[optind + i] == '-') break;
                 }
                 if ( strncmp(argv[optind], "track=", 6) == 0 ) {
                     char* trak_idx = argv[optind];
                     strsep(&trak_idx, "=");
-                    sscanf(trak_idx, "%" PRIu8 "", &selected_track);
+                    selected_track = strtoul(trak_idx, NULL, 10);
                     userdata_area = SINGLE_TRACK_ATOM;
                 } else if ( strcmp(argv[optind], "track") == 0 ) {
                     userdata_area = ALL_TRACKS_ATOM;
                     } else if ( strncmp(argv[optind + i], "domain=", 7) == 0 ) {
                         reverseDNS_atomdomain = argv[optind + i]+7;
                     } else if ( strncmp(argv[optind + i], "datatype=", 9) == 0 ) {
-                        sscanf(argv[optind + i]+9, "%u", &rdns_atom_flags);
+                        sscanf(argv[optind + i]+9, "%" SCNu32, &rdns_atom_flags);
                     }
                     if (*argv[optind + i] == '-') {
                         break; //we've hit another cli argument
 
                 const char* groupsymbol = find_ID3_optarg(argv, optind, "groupsymbol=");
                 if (groupsymbol[0] == '0' && groupsymbol[1] == 'x') {
-                    sscanf(groupsymbol, "%hhX", &id3args->groupSymbol);
+                    id3args->groupSymbol = strtoul(groupsymbol, NULL, 16);
                     if (id3args->groupSymbol < 0x80 || id3args->groupSymbol > 0xF0) id3args->groupSymbol = 0;
                 }
             }
 				if (eval_frame->ID3v2_FrameType == ID3_ATTACHED_PICTURE_FRAME) {
 					ImageFileFormatDefinition* thisimage = APar_ImageExtractTest((eval_frame->ID3v2_Frame_Fields+4)->field_string, NULL);
 					char* img_description = APar_ConvertField_to_UTF8(eval_frame, ID3_DESCRIPTION_FIELD);
-					sprintf(extract_filename+basepath_len, "-img#%u-(desc=%s)-0x%02X%s", 
+					sprintf(extract_filename+basepath_len, "-img#%u-(desc=%s)-0x%02X%s",
 				                                     iter, img_description, (uint8_t)((eval_frame->ID3v2_Frame_Fields+2)->field_string[0]), thisimage->image_fileextn);
 				
 					if (img_description != NULL) {
 			} else {
 				if ( (memcmp(parent_atom_name, "trkn", 4) == 0) || (memcmp(parent_atom_name, "disk", 4) == 0) ) {
 					if (UInt16FromBigEndian(data_payload+4) != 0) {
-						fprintf(stdout, "%hu of %hu\n", UInt16FromBigEndian(data_payload+2), UInt16FromBigEndian(data_payload+4) );
+						fprintf(stdout, "%u of %u\n", UInt16FromBigEndian(data_payload+2), UInt16FromBigEndian(data_payload+4) );
 					} else {
-						fprintf(stdout, "%hu\n", UInt16FromBigEndian(data_payload+2) );
+						fprintf(stdout, "%u\n", UInt16FromBigEndian(data_payload+2) );
 					}
 					
 				} else if (strncmp(parent_atom_name, "gnre", 4) == 0) {
 						if (genre_string != NULL) {
 							fprintf(stdout,"%s\n", genre_string);
 						} else {
-							fprintf(stdout," out of bound value - %hu\n", UInt16FromBigEndian(data_payload) );
+							fprintf(stdout," out of bound value - %u\n", UInt16FromBigEndian(data_payload) );
 						}
 					} else {
-						fprintf(stdout," out of bound value - %hu\n", UInt16FromBigEndian(data_payload) );
+						fprintf(stdout," out of bound value - %u\n", UInt16FromBigEndian(data_payload) );
 					}
 					
 				} else if ( (strncmp(parent_atom_name, "purl", 4) == 0) || (strncmp(parent_atom_name, "egid", 4) == 0) ) {
 									if (returned_stik != NULL) {
 										fprintf(stdout, "%s\n", returned_stik->stik_string);
 									} else {
-										fprintf(stdout, "Unknown value: %" PRIu8 "\n", (uint8_t)data_payload[0]);
+										fprintf(stdout, "Unknown value: %u\n", (uint8_t)data_payload[0]);
 									}
 									
 								} else if (strncmp(parent_atom_name, "rtng", 4) == 0) { //okay, this is definitely an 8-bit number
 									}
 									
 								} else {
-									fprintf(stdout, "%hhu\n", data_payload[0] );
+									fprintf(stdout, "%u\n", (uint8_t)data_payload[0] );
 								}
 								break;
 							}
 							case 2 : { //tmpo
-								fprintf(stdout, "%hu\n", UInt16FromBigEndian(data_payload) );
+								fprintf(stdout, "%u\n", UInt16FromBigEndian(data_payload) );
 								break;
 							}
 							case 4 : { //tves, tvsn
 								if (memcmp(parent_atom_name, "sfID", 4) == 0) {
 									sfIDs* this_store = MatchStoreFrontNumber( UInt32FromBigEndian(data_payload) );
 									if (this_store != NULL) {
-										fprintf(stdout, "%s (%u)\n", this_store->storefront_string, this_store->storefront_number );
+										fprintf(stdout, "%s (%" PRIu32 ")\n", this_store->storefront_string, this_store->storefront_number );
 									} else {
-										fprintf(stdout, "Unknown (%u)\n", UInt32FromBigEndian(data_payload) );
+										fprintf(stdout, "Unknown (%" PRIu32 ")\n", UInt32FromBigEndian(data_payload) );
 									}
 								
 								} else {
-									fprintf(stdout, "%u\n", UInt32FromBigEndian(data_payload) );
+									fprintf(stdout, "%" PRIu32 "\n", UInt32FromBigEndian(data_payload) );
 								}
 								break;
 							}
 		APar_Optimize(true); //just to know if 'free' atoms can be considered padding, or (in the case of say a faac file) it's *just* 'free'
 		
 		if (supplemental_info && 0x02) { //PRINT_FREE_SPACE
-			fprintf(stdout, "free atom space: %u\n", APar_ProvideTallyForAtom("free") );
+			fprintf(stdout, "free atom space: %" PRIu32 "\n", APar_ProvideTallyForAtom("free") );
 		}
 		if (supplemental_info && 0x04) { //PRINT_PADDING_SPACE
 			if (!moov_atom_was_mooved) {
 			fprintf(stdout, "user data space: %" PRIu64 "\n", dynUpd.moov_udta_atom->AtomicLength);
 		}
 		if (supplemental_info && 0x10) { //PRINT_USER_DATA_SPACE
-			fprintf(stdout, "media data space: %u\n", APar_ProvideTallyForAtom("mdat") );
+			fprintf(stdout, "media data space: %" PRIu32 "\n", APar_ProvideTallyForAtom("mdat") );
 		}
 	}
 	
 			APar_readX(box_data, source_file, parsedAtoms[userdata_atom].AtomicStart + 12, 4);
 			
 			fprintf(stdout, "[Rating Entity=%s", box_data);
-			//fprintf(stdout, " Rating Criteria: %u%u%u%u", box_data[4], box_data[5], box_data[6], box_data[7]);
 			memset(box_data, 0, box_length);
 			APar_readX(box_data, source_file, parsedAtoms[userdata_atom].AtomicStart + 16, 4);
 			fprintf(stdout, " | Criteria=%s", box_data);
 	} else if (textframe->ID3v2_Frame_Fields->field_string[0] == TE_UTF8) {
 		fprintf(stdout, "%s", textfield->field_string);
 	} else {
-		fprintf(stdout, "(unknown type: 0x%X", textframe->ID3v2_Frame_Fields->field_string[0]);
+		fprintf(stdout, "(unknown type: 0x%X", (uint8_t)textframe->ID3v2_Frame_Fields->field_string[0]);
 	}
 	if(linefeed) fprintf(stdout, "\n");
 	return;
 	} else {
 		fprintf(stdout, "ID32 atom [lang=%s] at %s contains an ID3v2.%u.%u tag. ", unpacked_lang, id32_level, id32_atom->ID32_TagInfo->ID3v2Tag_MajorVersion, id32_atom->ID32_TagInfo->ID3v2Tag_RevisionVersion);
 		if (ID3v2_TestTagFlag(id32_atom->ID32_TagInfo->ID3v2Tag_Flags, ID32_TAGFLAG_UNSYNCRONIZATION)) {
-			fprintf(stdout, "Unsyncrhonized flag set. Unsupported. No tags read. %u bytes.\n", id32_atom->ID32_TagInfo->ID3v2Tag_Length);
+			fprintf(stdout, "Unsynchronized flag set. Unsupported. No tags read. %" PRIu32 " bytes.\n", id32_atom->ID32_TagInfo->ID3v2Tag_Length);
 		}
 	}
 	
 		}
 		uint8_t frame_comp_idx = GetFrameCompositionDescription(target_frameinfo->ID3v2_FrameType);
 		if (FrameTypeConstructionList[frame_comp_idx].ID3_FrameType == ID3_UNKNOWN_FRAME) {
-			fprintf(stdout, "(unknown frame) %u bytes\n", target_frameinfo->ID3v2_Frame_Fields->field_length);
+			fprintf(stdout, "(unknown frame) %" PRIu32 " bytes\n", target_frameinfo->ID3v2_Frame_Fields->field_length);
 			
 		} else if (FrameTypeConstructionList[frame_comp_idx].ID3_FrameType == ID3_TEXT_FRAME) {
 			ID3v2Fields* atextfield = target_frameinfo->ID3v2_Frame_Fields+1;
 			APar_Print_ID3TextField(target_frameinfo, target_frameinfo->ID3v2_Frame_Fields+3, true);
 				
 		} else if (FrameTypeConstructionList[frame_comp_idx].ID3_FrameType == ID3_ATTACHED_PICTURE_FRAME) {
-			fprintf(stdout, "(type=0x%02X-'%s', mimetype=%s, %s, desc[", (target_frameinfo->ID3v2_Frame_Fields+2)->field_string[0],
+			fprintf(stdout, "(type=0x%02X-'%s', mimetype=%s, %s, desc[", (uint8_t)(target_frameinfo->ID3v2_Frame_Fields+2)->field_string[0],
 			                 ImageTypeList[ (uint8_t)(target_frameinfo->ID3v2_Frame_Fields+2)->field_string[0] ].imagetype_str, (target_frameinfo->ID3v2_Frame_Fields+1)->field_string,
 											 APar_GetTextEncoding(target_frameinfo, target_frameinfo->ID3v2_Frame_Fields+1)  );
 			APar_Print_ID3TextField(target_frameinfo, target_frameinfo->ID3v2_Frame_Fields+3);
 			if (ID3v2_TestFrameFlag(target_frameinfo->ID3v2_Frame_Flags, ID32_FRAMEFLAG_COMPRESSED)) {
-				fprintf(stdout, "]) : %u bytes (%u compressed)\n",
+				fprintf(stdout, "]) : %" PRIu32 " bytes (%" PRIu32 " compressed)\n",
 				                     (target_frameinfo->ID3v2_Frame_Fields+4)->field_length, target_frameinfo->ID3v2_Frame_Length);
 			} else {
-				fprintf(stdout, "]) : %u bytes\n", (target_frameinfo->ID3v2_Frame_Fields+4)->field_length);
+				fprintf(stdout, "]) : %" PRIu32 " bytes\n", (target_frameinfo->ID3v2_Frame_Fields+4)->field_length);
 			}
 
 		} else if (target_frameinfo->ID3v2_FrameType == ID3_ATTACHED_OBJECT_FRAME) {
 			fprintf(stdout, ", mimetype=%s, desc[", (target_frameinfo->ID3v2_Frame_Fields+1)->field_string);
 			APar_Print_ID3TextField(target_frameinfo, target_frameinfo->ID3v2_Frame_Fields+3);
 			if (ID3v2_TestFrameFlag(target_frameinfo->ID3v2_Frame_Flags, ID32_FRAMEFLAG_COMPRESSED)) {
-				fprintf(stdout, "]) : %u bytes (%u compressed)\n",
+				fprintf(stdout, "]) : %" PRIu32 " bytes (%" PRIu32 " compressed)\n",
 				                     (target_frameinfo->ID3v2_Frame_Fields+4)->field_length, target_frameinfo->ID3v2_Frame_Length);
 			} else {
-				fprintf(stdout, "]) : %u bytes\n", (target_frameinfo->ID3v2_Frame_Fields+4)->field_length);
+				fprintf(stdout, "]) : %" PRIu32 " bytes\n", (target_frameinfo->ID3v2_Frame_Fields+4)->field_length);
 			}
 		
 		} else if (target_frameinfo->ID3v2_FrameType == ID3_GROUP_ID_FRAME) {
 		
 		} else if (target_frameinfo->ID3v2_FrameType == ID3_PLAYCOUNTER_FRAME) {
 			if (target_frameinfo->ID3v2_Frame_Fields->field_length == 4) {
-				fprintf(stdout, ": %u\n", syncsafe32_to_UInt32(target_frameinfo->ID3v2_Frame_Fields->field_string) );
+				fprintf(stdout, ": %" PRIu32 "\n", syncsafe32_to_UInt32(target_frameinfo->ID3v2_Frame_Fields->field_string) );
 			} else if (target_frameinfo->ID3v2_Frame_Fields->field_length > 4) {
 				fprintf(stdout, ": %" PRIu64 "\n", syncsafeXX_to_UInt64(target_frameinfo->ID3v2_Frame_Fields->field_string, target_frameinfo->ID3v2_Frame_Fields->field_length) );
 			}
 		
 		} else if (target_frameinfo->ID3v2_FrameType == ID3_POPULAR_FRAME) {
-			fprintf(stdout, "(owner='%s') : %u", target_frameinfo->ID3v2_Frame_Fields->field_string, (target_frameinfo->ID3v2_Frame_Fields+1)->field_string[0]);
+			fprintf(stdout, "(owner='%s') : %u", target_frameinfo->ID3v2_Frame_Fields->field_string, (uint8_t)(target_frameinfo->ID3v2_Frame_Fields+1)->field_string[0]);
 			if ((target_frameinfo->ID3v2_Frame_Fields+2)->field_length > 0) {
 				if ((target_frameinfo->ID3v2_Frame_Fields+2)->field_length == 4) {
-					fprintf(stdout, "; playcount=%u\n", syncsafe32_to_UInt32((target_frameinfo->ID3v2_Frame_Fields+2)->field_string));
+					fprintf(stdout, "; playcount=%" PRIu32 "\n", syncsafe32_to_UInt32((target_frameinfo->ID3v2_Frame_Fields+2)->field_string));
 				} else if ((target_frameinfo->ID3v2_Frame_Fields+2)->field_length > 4) {
 					fprintf(stdout, "; playcount=%" PRIu64 "\n", syncsafeXX_to_UInt64((target_frameinfo->ID3v2_Frame_Fields+2)->field_string, (target_frameinfo->ID3v2_Frame_Fields+2)->field_length));
 				} else {
 			if (UnicodeOutputStatus == WIN32_UTF16) {
 				fprintf(stdout, "%sAtom ", tree_padding);
 				APar_fprintf_UTF8_data(twenty_byte_buffer);
-				fprintf(stdout, " @ %" PRIu64 " of size: %" PRIu64 ", ends @ %" PRIu64 "", thisAtom->AtomicStart, thisAtom->AtomicLength, (thisAtom->AtomicStart + thisAtom->AtomicLength) );
+				fprintf(stdout, " @ %" PRIu64 " of size: %" PRIu64 ", ends @ %" PRIu64, thisAtom->AtomicStart, thisAtom->AtomicLength, (thisAtom->AtomicStart + thisAtom->AtomicLength) );
 			} else {
-				fprintf(stdout, "%sAtom %s @ %" PRIu64 " of size: %" PRIu64 ", ends @ %" PRIu64 "", tree_padding, twenty_byte_buffer, thisAtom->AtomicStart, thisAtom->AtomicLength, (thisAtom->AtomicStart + thisAtom->AtomicLength) );
+				fprintf(stdout, "%sAtom %s @ %" PRIu64 " of size: %" PRIu64 ", ends @ %" PRIu64, tree_padding, twenty_byte_buffer, thisAtom->AtomicStart, thisAtom->AtomicLength, (thisAtom->AtomicStart + thisAtom->AtomicLength) );
 			}
 
 			if (thisAtom->AtomicContainerState == UNKNOWN_ATOM_TYPE) {
 		mdatData, file_size - mdatData,
 		(double)(file_size - mdatData)/(double)file_size * 100.0 );
 
-	fprintf(stdout, "Total free atom space: %u bytes; %2.3lf%% waste.",
+	fprintf(stdout, "Total free atom space: %" PRIu32 " bytes; %2.3lf%% waste.",
 		freeSpace, (double)freeSpace/(double)file_size * 100.0 );
 
 	if (freeSpace) {
 
 	APar_FindAtomInTrack(total_tracks, a_track, NULL); //gets the number of tracks
 	for (uint8_t trk_idx=1; trk_idx <= total_tracks; trk_idx++) {
-		sprintf(track_path, "moov.trak[%hhu].mdia.minf.stbl", trk_idx);
+		sprintf(track_path, "moov.trak[%u].mdia.minf.stbl", trk_idx);
 		samples_parent = APar_FindAtom(track_path, false, SIMPLE_ATOM, 0, false);
 		if (samples_parent != NULL) {
 			chunk_offset_atom = APar_FindChildAtom(samples_parent->AtomicNumber, "stco");
 		}
 
 		if ( memcmp(parsedAtoms[eval_atom].AtomicName, "free", 4) == 0 || memcmp(parsedAtoms[eval_atom].AtomicName, "skip", 4) == 0 ) {
-			//fprintf(stdout, "i am of size %u purge level %i (%u) -> %i\n", parsedAtoms[eval_atom].AtomicLength, purge_level, parsedAtoms[eval_atom].AtomicLevel, eval_atom);
+			//fprintf(stdout, "i am of size %" PRIu64 " purge level %i (%u) -> %i\n", parsedAtoms[eval_atom].AtomicLength, purge_level, parsedAtoms[eval_atom].AtomicLevel, eval_atom);
 			if ( purge_level == -1 || purge_level >= parsedAtoms[eval_atom].AtomicLevel ||
 			     (purge_level == 0 && parsedAtoms[eval_atom].AtomicLevel == 1 && (moov_atom == 0 || mdat_atom != 0)) ) {
 				short prev_atom = APar_FindPrecedingAtom(eval_atom);
 
 	} else {
 		if ( !(dataType == AtomFlags_Data_Text || dataType == AtomFlags_Data_uuid_binary) ) { //the only supported types
-			fprintf(stdout, "AP warning: only text or file types are allowed on uuid atom %s (%u-%u); skipping\n", uuidName, dataType, AtomFlags_Data_Text);
+			fprintf(stdout, "AP warning: only text or file types are allowed on uuid atom %s (%" PRIu32 "-%u); skipping\n", uuidName, dataType, AtomFlags_Data_Text);
 			return NULL;
 		}
 		//uuid atoms won't have 'data' child atoms - they will carry the data directly as opposed to traditional iTunes-style metadata that does store the information on 'data' atoms. But user-defined is user-defined, so that is how it will be defined here.
 	while (true) {
 		if (parsedAtoms[stop_atom].AtomicLevel == 1) {
 			byte_sum+= (parsedAtoms[stop_atom].AtomicLength == 1 ? parsedAtoms[stop_atom].AtomicLengthExtended : parsedAtoms[stop_atom].AtomicLength);
-			//fprintf(stdout, "%i %s (%u)\n", stop_atom, parsedAtoms[stop_atom].AtomicName, parsedAtoms[stop_atom].AtomicLength);
+			//fprintf(stdout, "%i %s (%" PRIu64 ")\n", stop_atom, parsedAtoms[stop_atom].AtomicName, parsedAtoms[stop_atom].AtomicLength);
 		}
 		if (stop_atom == 0) {
 			break;
 			} //for loop extent
 
 #if defined(DEBUG_V)
-			fprintf(stdout, "debug: AP_Readjust_iloc_atom  iloc's %u index at base offset: %u, total bytes %u\n", an_item_ID, base_offset, extent_len_sum);
+			fprintf(stdout, "debug: AP_Readjust_iloc_atom  iloc's %u index at base offset: %" PRIu64 ", total bytes %" PRIu64 "\n", an_item_ID, base_offset, extent_len_sum);
 #endif
 			AtomicInfo* container_atom = APar_Constituent_mdat_data(base_offset, 0x013077 );
 
 				uint64_t new_item_offset = curr_container_pos + exisiting_offset_into_atom;
 
 #if defined(DEBUG_V)
-				fprintf(stdout, "debug: AP_Readjust_iloc_atom  item is contained on mdat started @ %u (now at %u)\n", container_atom->AtomicStart, curr_container_pos);
-				fprintf(stdout, "debug: AP_Readjust_iloc_atom  item is %u bytes offset into atom (was %u, now %u)\n", exisiting_offset_into_atom, base_offset, new_item_offset);
+				fprintf(stdout, "debug: AP_Readjust_iloc_atom  item is contained on mdat started @ %" PRIu64 " (now at %" PRIu64 ")\n", container_atom->AtomicStart, curr_container_pos);
+				fprintf(stdout, "debug: AP_Readjust_iloc_atom  item is %" PRIu64 " bytes offset into atom (was %" PRIu64 ", now %" PRIu64 ")\n", exisiting_offset_into_atom, base_offset, new_item_offset);
 #endif
 				if (base_offset_size == 4) {
 					UInt32_TO_String4(new_item_offset, base_offset_ptr);
 		}
 
 		while (parsedAtoms[next_atom].AtomicLevel > parsedAtoms[rev_atom_loop].AtomicLevel) { // eval all child atoms....
-			//fprintf(stdout, "\ttest child atom %s, level:%i (sum %u)\n", parsedAtoms[next_atom].AtomicName, parsedAtoms[next_atom].AtomicLevel, atom_size);
+			//fprintf(stdout, "\ttest child atom %s, level:%i (sum %" PRIu64 ")\n", parsedAtoms[next_atom].AtomicName, parsedAtoms[next_atom].AtomicLevel, atom_size);
 			if (parsedAtoms[rev_atom_loop].AtomicLevel == ( parsedAtoms[next_atom].AtomicLevel - 1) ) { // only child atoms 1 level down
 				atom_size += parsedAtoms[next_atom].AtomicLength;
-				//fprintf(stdout, "\t\teval child atom %s, level:%i (sum %u)\n", parsedAtoms[next_atom].AtomicName, parsedAtoms[next_atom].AtomicLevel, atom_size);
-				//fprintf(stdout, "\t\teval %s's child atom %s, level:%i (sum %u, added %u)\n", parsedAtoms[previous_atom].AtomicName, parsedAtoms[next_atom].AtomicName, parsedAtoms[next_atom].AtomicLevel, atom_size, parsedAtoms[next_atom].AtomicLength);
+				//fprintf(stdout, "\t\teval child atom %s, level:%i (sum %" PRIu64 ")\n", parsedAtoms[next_atom].AtomicName, parsedAtoms[next_atom].AtomicLevel, atom_size);
+				//fprintf(stdout, "\t\teval %s's child atom %s, level:%i (sum %" PRIu64 ", added %" PRIu64 ")\n", parsedAtoms[previous_atom].AtomicName, parsedAtoms[next_atom].AtomicName, parsedAtoms[next_atom].AtomicLevel, atom_size, parsedAtoms[next_atom].AtomicLength);
 			} else if (parsedAtoms[next_atom].AtomicLevel < parsedAtoms[rev_atom_loop].AtomicLevel) {
 				break;
 			}
 		if (parsedAtoms[iter].AtomicLength > file_size && file_size > 300000) {
 			if (parsedAtoms[iter].AtomicData == NULL) {
 				fprintf(stderr, "AtomicParsley error: an atom was detected that presents as larger than filesize. Aborting. %c\n", '\a');
-#if defined (_WIN32) && !defined (__CYGWIN__) /* apparently, long long is forbidden there*/
-				fprintf(stderr, "atom %s is %I64u\n bytes long which is greater than the filesize of %I64u\n", parsedAtoms[iter].AtomicName, parsedAtoms[iter].AtomicLength, file_size);
-#else
 				fprintf(stderr, "atom %s is %" PRIu64 " bytes long which is greater than the filesize of %" PRIu64 "\n", parsedAtoms[iter].AtomicName, parsedAtoms[iter].AtomicLength, file_size);
-#endif
 				exit(1); //its conceivable to repair such an off length by the surrounding atoms constrained by file_size - just not anytime soon; probly would catch a foobar2000 0.9 tagged file
 			}
 		}
 		if (parsedAtoms[this_atom].AtomicClassification == EXTENDED_ATOM) {
 			fwrite("uuid", 4, 1, temp_file);
 			atom_name_len = 16; //total of 20 bytes for a uuid atom
-			//fprintf(stdout, "%u\n", parsedAtoms[this_atom].AtomicLength);
+			//fprintf(stdout, "%" PRIu64 "\n", parsedAtoms[this_atom].AtomicLength);
 			if (parsedAtoms[this_atom].AtomicClassification == EXTENDED_ATOM && parsedAtoms[this_atom].uuid_style == UUID_OTHER) bytes_written += 4;
 		}
 
 	size_t size;
 	size = fread(buffer, 1, length, ISObasemediafile);
 	if(size != length) {
-		printf("%s read failed, expect %u, got %u: %s\n", __FUNCTION__, length, (unsigned int)size, APar_strferror(ISObasemediafile));
+		printf("%s read failed, expect %" PRIu32 ", got %" PRIu32 ": %s\n", __FUNCTION__, length, (uint32_t)size, APar_strferror(ISObasemediafile));
 		exit(1);
 	}
 	return;
 	fseeko(ISObasemediafile, pos, SEEK_SET);
 	size = fread(buffer, 1, length, ISObasemediafile);
 	if(size != length) {
-		printf("%s read failed, expect %u, got %u: %s\n", __FUNCTION__, length, (unsigned int) size, APar_strferror(ISObasemediafile));
+		printf("%s read failed, expect %" PRIu32 ", got %" PRIu32 ": %s\n", __FUNCTION__, length, (uint32_t)size, APar_strferror(ISObasemediafile));
 		exit(1);
 	}
 	return;
 		Print out a full string representation of a uuid
 ----------------------*/
 void APar_print_uuid(ap_uuid_t* uuid, bool new_line) {
-	fprintf(stdout, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+	fprintf(stdout, "%08" PRIx32 "-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
 									uuid->time_low,
 									uuid->time_mid,
 									uuid->time_hi_and_version,
 		Put a binary representation of a uuid to a human-readable ordered uuid string
 ----------------------*/
 void APar_sprintf_uuid(ap_uuid_t* uuid, char* destination) {
-	sprintf(destination, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+	sprintf(destination, "%08" PRIx32 "-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
 									uuid->time_low,
 									uuid->time_mid,
 									uuid->time_hi_and_version,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.