# HG changeset patch # User Matti Hamalainen # Date 1503180072 -10800 # Node ID dce4730372c76c0e30915e960d05924f08e723de # Parent 5ad7d780a09b758084ace054ee4d16aceeef9328 Add some blocks, cosmetics. diff -r 5ad7d780a09b -r dce4730372c7 minijss/jloadjss.c --- a/minijss/jloadjss.c Sat Aug 19 15:27:43 2017 +0300 +++ b/minijss/jloadjss.c Sun Aug 20 01:01:12 2017 +0300 @@ -329,8 +329,10 @@ if (probe) return DMERR_NOT_SUPPORTED; else + { JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED, "Not a JSSMOD file, header signature mismatch!\n"); + } } if (jssH.idVersion != JSSMOD_VERSION) @@ -338,9 +340,11 @@ if (probe) return DMERR_VERSION; else - JSSERROR(DMERR_VERSION, DMERR_VERSION, - "Unsupported version of JSSMOD 0x%2x, this version only supports 0x%2x!\n", - jssH.idVersion, JSSMOD_VERSION); + { + JSSERROR(DMERR_VERSION, DMERR_VERSION, + "Unsupported version of JSSMOD 0x%2x, this version only supports 0x%2x!\n", + jssH.idVersion, JSSMOD_VERSION); + } } // Read rest of the header @@ -351,12 +355,15 @@ !dmf_read_le16(inFile, &jssH.nextInstruments) || !dmf_read_le16(inFile, &jssH.ninstruments) || !dmf_read_le16(inFile, &jssH.defRestartPos) || + !dmf_read_byte(inFile, &jssH.nchannels) || !dmf_read_byte(inFile, &jssH.defSpeed) || !dmf_read_byte(inFile, &jssH.defTempo) || !dmf_read_byte(inFile, &jssH.patMode)) + { JSSERROR(DMERR_FREAD, DMERR_FREAD, "Failed to read JSSMOD header #2.\n"); + } if (probe) return DMERR_OK; @@ -431,9 +438,11 @@ // Allocate pattern pattern = module->patterns[index] = jssAllocatePattern(jssP.nrows, module->nchannels); if (pattern == NULL) + { JSSERROR(DMERR_MALLOC, DMERR_MALLOC, "Could not allocate memory for pattern #%d.\n", index); + } // Get pattern data switch (jssH.patMode) diff -r 5ad7d780a09b -r dce4730372c7 tools/xm2jss.c --- a/tools/xm2jss.c Sat Aug 19 15:27:43 2017 +0300 +++ b/tools/xm2jss.c Sun Aug 20 01:01:12 2017 +0300 @@ -463,16 +463,20 @@ // Check the module if (module == NULL) + { JSSERROR(DMERR_NULLPTR, DMERR_NULLPTR, "Module pointer was NULL\n"); + } if (module->nchannels < 1 || module->npatterns < 1 || module->norders < 1 || module->nchannels > jsetMaxChannels || module->npatterns > jsetMaxPatterns || module->norders > jsetMaxOrders) + { JSSERROR(DMERR_BOUNDS, DMERR_BOUNDS, "Module had invalid values (nchannels=%d, npatterns=%d, norders=%d)\n", module->nchannels, module->npatterns, module->norders); + } // Create the JSSMOD header jssH.idMagic[0] = 'J'; @@ -507,8 +511,10 @@ !dm_fwrite_byte(outFile, jssH.defSpeed) || !dm_fwrite_byte(outFile, jssH.defTempo) || !dm_fwrite_byte(outFile, jssH.patMode)) + { JSSERROR(DMERR_FWRITE, DMERR_FWRITE, "Error writing JSSMOD header!\n"); + } totalSize = sizeof(jssH); dmMsg(1," * JSSMOD-header 0x%04x, %d bytes.\n", JSSMOD_VERSION, totalSize); @@ -518,9 +524,11 @@ { int tmp = module->orderList[index]; if (tmp != jsetNotSet && tmp > module->npatterns) + { JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, "Orderlist entry #%d has invalid value %d.\n", index, tmp); + } if (tmp == jsetNotSet) tmp = 0xffff; @@ -538,8 +546,10 @@ // Allocate pattern compression buffer if ((patBuf = dmMalloc(patBufSize)) == NULL) + { JSSERROR(DMERR_MALLOC, DMERR_MALLOC, "Error allocating memory for pattern compression buffer.\n"); + } // Convert and write patterns for (totalSize = index = 0; index < module->npatterns; index++) @@ -550,9 +560,11 @@ int ret; if (pattern->nrows > jsetMaxRows) + { JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA, "Pattern #%d has %d rows > %d max.\n", index, pattern->nrows, jsetMaxRows); + } switch (patMode) { @@ -578,8 +590,10 @@ } if (ret != DMERR_OK) + { JSSERROR(ret, ret, "Error converting pattern data #%d.\n", pattern); + } dmMsg(3, " - Pattern %d size %d bytes\n", index, dataSize); totalSize += dataSize + sizeof(JSSMODPattern); @@ -587,13 +601,17 @@ if (!dm_fwrite_le32(outFile, dataSize) || !dm_fwrite_le16(outFile, pattern->nrows) || !dm_fwrite_str(outFile, patBuf, dataSize)) + { JSSERROR(DMERR_FWRITE, DMERR_FWRITE, "Error writing JSSMOD pattern #%d.\n", index); + } } else + { JSSERROR(DMERR_NULLPTR, DMERR_NULLPTR, "Pattern #%d was NULL.\n", index); + } dmFree(patBuf); dmMsg(1," * %d patterns, %d bytes.\n", @@ -624,16 +642,20 @@ if (!ok || !jssMODWriteEnvelope(outFile, &einst->volumeEnv, "volume", index) || !jssMODWriteEnvelope(outFile, &einst->panningEnv, "panning", index)) + { JSSERROR(DMERR_FWRITE, DMERR_FWRITE, "Error writing JSSMOD extended instrument #%d.\n", index); + } totalSize += sizeof(JSSMODExtInstrument); } else + { JSSWARNING(DMERR_NULLPTR, DMERR_NULLPTR, "Extended instrument #%d NULL!\n", index); + } dmMsg(1," * %d Extended Instruments, %d bytes.\n", module->nextInstruments, totalSize); @@ -658,15 +680,19 @@ !dm_fwrite_le16(outFile, inst->EPanning) || !dm_fwrite_byte(outFile, inst->volume) || !dm_fwrite_byte(outFile, inst->convFlags)) + { JSSERROR(DMERR_FWRITE, DMERR_FWRITE, "Error writing JSSMOD instrument #%d.\n", index); + } totalSize += sizeof(JSSMODInstrument); } else + { JSSWARNING(DMERR_NULLPTR, DMERR_NULLPTR, "Instrument #%d NULL!\n", index); + } dmMsg(1," * %d Instrument headers, %d bytes.\n", module->ninstruments, totalSize); @@ -690,9 +716,11 @@ } if (!dm_fwrite_str(outFile, inst->data, bsize)) + { JSSERROR(DMERR_FWRITE, DMERR_FWRITE, "Error writing JSSMOD sample data for instrument #%d.\n", index); + } totalSize += bsize; }