comparison ifo_read.c @ 68:3748dde919dd src

Clean up error paths. Clean up the error paths of the function using goto.
author erik
date Sat, 13 Aug 2011 17:28:40 +0000
parents 8fab3ce417ed
children d35a5dd07b34
comparison
equal deleted inserted replaced
67:8fab3ce417ed 68:3748dde919dd
1137 } 1137 }
1138 } 1138 }
1139 1139
1140 1140
1141 int ifoRead_VTS_PTT_SRPT(ifo_handle_t *ifofile) { 1141 int ifoRead_VTS_PTT_SRPT(ifo_handle_t *ifofile) {
1142 vts_ptt_srpt_t *vts_ptt_srpt; 1142 vts_ptt_srpt_t *vts_ptt_srpt = NULL;
1143 int info_length, i, j; 1143 int info_length, i, j;
1144 uint32_t *data = NULL; 1144 uint32_t *data = NULL;
1145 1145
1146 if(!ifofile) 1146 if(!ifofile)
1147 return 0; 1147 return 0;
1162 1162
1163 ifofile->vts_ptt_srpt = vts_ptt_srpt; 1163 ifofile->vts_ptt_srpt = vts_ptt_srpt;
1164 1164
1165 if(!(DVDReadBytes(ifofile->file, vts_ptt_srpt, VTS_PTT_SRPT_SIZE))) { 1165 if(!(DVDReadBytes(ifofile->file, vts_ptt_srpt, VTS_PTT_SRPT_SIZE))) {
1166 fprintf(stderr, "libdvdread: Unable to read PTT search table.\n"); 1166 fprintf(stderr, "libdvdread: Unable to read PTT search table.\n");
1167 free(vts_ptt_srpt); 1167 goto fail;
1168 return 0;
1169 } 1168 }
1170 1169
1171 B2N_16(vts_ptt_srpt->nr_of_srpts); 1170 B2N_16(vts_ptt_srpt->nr_of_srpts);
1172 B2N_32(vts_ptt_srpt->last_byte); 1171 B2N_32(vts_ptt_srpt->last_byte);
1173 1172
1176 CHECK_VALUE(vts_ptt_srpt->nr_of_srpts < 100); /* ?? */ 1175 CHECK_VALUE(vts_ptt_srpt->nr_of_srpts < 100); /* ?? */
1177 1176
1178 info_length = vts_ptt_srpt->last_byte + 1 - VTS_PTT_SRPT_SIZE; 1177 info_length = vts_ptt_srpt->last_byte + 1 - VTS_PTT_SRPT_SIZE;
1179 data = malloc(info_length); 1178 data = malloc(info_length);
1180 if(!data) { 1179 if(!data) {
1181 free(vts_ptt_srpt); 1180 goto fail;
1182 ifofile->vts_ptt_srpt = 0;
1183 return 0;
1184 } 1181 }
1185 if(!(DVDReadBytes(ifofile->file, data, info_length))) { 1182 if(!(DVDReadBytes(ifofile->file, data, info_length))) {
1186 fprintf(stderr, "libdvdread: Unable to read PTT search table.\n"); 1183 fprintf(stderr, "libdvdread: Unable to read PTT search table.\n");
1187 free(vts_ptt_srpt); 1184 goto fail;
1188 free(data);
1189 ifofile->vts_ptt_srpt = 0;
1190 return 0;
1191 } 1185 }
1192 1186
1193 for(i = 0; i < vts_ptt_srpt->nr_of_srpts; i++) { 1187 for(i = 0; i < vts_ptt_srpt->nr_of_srpts; i++) {
1194 B2N_32(data[i]); 1188 B2N_32(data[i]);
1195 /* assert(data[i] + sizeof(ptt_info_t) <= vts_ptt_srpt->last_byte + 1); 1189 /* assert(data[i] + sizeof(ptt_info_t) <= vts_ptt_srpt->last_byte + 1);
1201 1195
1202 vts_ptt_srpt->ttu_offset = data; 1196 vts_ptt_srpt->ttu_offset = data;
1203 1197
1204 vts_ptt_srpt->title = malloc(vts_ptt_srpt->nr_of_srpts * sizeof(ttu_t)); 1198 vts_ptt_srpt->title = malloc(vts_ptt_srpt->nr_of_srpts * sizeof(ttu_t));
1205 if(!vts_ptt_srpt->title) { 1199 if(!vts_ptt_srpt->title) {
1206 free(vts_ptt_srpt); 1200 goto fail;
1207 free(data);
1208 ifofile->vts_ptt_srpt = 0;
1209 return 0;
1210 } 1201 }
1211 for(i = 0; i < vts_ptt_srpt->nr_of_srpts; i++) { 1202 for(i = 0; i < vts_ptt_srpt->nr_of_srpts; i++) {
1212 int n; 1203 int n;
1213 if(i < vts_ptt_srpt->nr_of_srpts - 1) 1204 if(i < vts_ptt_srpt->nr_of_srpts - 1)
1214 n = (data[i+1] - data[i]); 1205 n = (data[i+1] - data[i]);
1223 vts_ptt_srpt->title[i].nr_of_ptts = n / 4; 1214 vts_ptt_srpt->title[i].nr_of_ptts = n / 4;
1224 vts_ptt_srpt->title[i].ptt = malloc(n * sizeof(ptt_info_t)); 1215 vts_ptt_srpt->title[i].ptt = malloc(n * sizeof(ptt_info_t));
1225 if(!vts_ptt_srpt->title[i].ptt) { 1216 if(!vts_ptt_srpt->title[i].ptt) {
1226 for(n = 0; n < i; n++) 1217 for(n = 0; n < i; n++)
1227 free(vts_ptt_srpt->title[n].ptt); 1218 free(vts_ptt_srpt->title[n].ptt);
1228 free(vts_ptt_srpt); 1219
1229 free(data); 1220 goto fail;
1230 ifofile->vts_ptt_srpt = 0;
1231 return 0;
1232 } 1221 }
1233 for(j = 0; j < vts_ptt_srpt->title[i].nr_of_ptts; j++) { 1222 for(j = 0; j < vts_ptt_srpt->title[i].nr_of_ptts; j++) {
1234 /* The assert placed here because of Magic Knight Rayearth Daybreak */ 1223 /* The assert placed here because of Magic Knight Rayearth Daybreak */
1235 CHECK_VALUE(data[i] + sizeof(ptt_info_t) <= vts_ptt_srpt->last_byte + 1); 1224 CHECK_VALUE(data[i] + sizeof(ptt_info_t) <= vts_ptt_srpt->last_byte + 1);
1236 vts_ptt_srpt->title[i].ptt[j].pgcn 1225 vts_ptt_srpt->title[i].ptt[j].pgcn
1256 CHECK_VALUE(vts_ptt_srpt->title[i].ptt[j].pgn < 100); /* ?? */ 1245 CHECK_VALUE(vts_ptt_srpt->title[i].ptt[j].pgn < 100); /* ?? */
1257 } 1246 }
1258 } 1247 }
1259 1248
1260 return 1; 1249 return 1;
1250
1251 fail:
1252 free(data);
1253 ifofile->vts_ptt_srpt = 0;
1254 free(vts_ptt_srpt);
1255 return 0;
1261 } 1256 }
1262 1257
1263 1258
1264 void ifoFree_VTS_PTT_SRPT(ifo_handle_t *ifofile) { 1259 void ifoFree_VTS_PTT_SRPT(ifo_handle_t *ifofile) {
1265 if(!ifofile) 1260 if(!ifofile)