mirror of
				https://github.com/vdr-projects/vdr.git
				synced 2025-03-01 10:50:46 +00:00 
			
		
		
		
	Changed offset and size handling in 'libsi' from 'unsigned' to 'signed', so that overflows can be better detected
This commit is contained in:
		
							
								
								
									
										4
									
								
								HISTORY
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								HISTORY
									
									
									
									
									
								
							| @@ -4317,7 +4317,7 @@ Video Disk Recorder Revision History | |||||||
| - Added cSkin::GetTextAreaWidth() and cSkin::GetTextAreaFont(), so that a plugin | - Added cSkin::GetTextAreaWidth() and cSkin::GetTextAreaFont(), so that a plugin | ||||||
|   that wants to do special text formatting can do so (thanks to Alexander Rieger). |   that wants to do special text formatting can do so (thanks to Alexander Rieger). | ||||||
|  |  | ||||||
| 2006-02-17: Version 1.3.43 | 2006-02-18: Version 1.3.43 | ||||||
|  |  | ||||||
| - Removed an unnecessary toFile->SetReadAhead() from cutter.c (thanks to Artur | - Removed an unnecessary toFile->SetReadAhead() from cutter.c (thanks to Artur | ||||||
|   Skawina). |   Skawina). | ||||||
| @@ -4332,3 +4332,5 @@ Video Disk Recorder Revision History | |||||||
| - cMenuText now uses the given font (thanks to Rolf Ahrenberg). | - cMenuText now uses the given font (thanks to Rolf Ahrenberg). | ||||||
| - The ST:TNG skin now uses the fixed font if requested when displaying texts. | - The ST:TNG skin now uses the fixed font if requested when displaying texts. | ||||||
| - Fixed some typos in the CONTRIBUTORS file (thanks to Frank Kr<4B>mmelbein). | - Fixed some typos in the CONTRIBUTORS file (thanks to Frank Kr<4B>mmelbein). | ||||||
|  | - Changed offset and size handling in 'libsi' from 'unsigned' to 'signed', so that | ||||||
|  |   overflows can be better detected (thanks to Marcel Wiesweg). | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ | |||||||
|  *   the Free Software Foundation; either version 2 of the License, or     * |  *   the Free Software Foundation; either version 2 of the License, or     * | ||||||
|  *   (at your option) any later version.                                   * |  *   (at your option) any later version.                                   * | ||||||
|  *                                                                         * |  *                                                                         * | ||||||
|  *   $Id: descriptor.c 1.15 2005/09/03 15:16:49 kls Exp $ |  *   $Id: descriptor.c 1.16 2006/02/18 10:38:20 kls Exp $ | ||||||
|  *                                                                         * |  *                                                                         * | ||||||
|  ***************************************************************************/ |  ***************************************************************************/ | ||||||
|  |  | ||||||
| @@ -16,7 +16,7 @@ | |||||||
| namespace SI { | namespace SI { | ||||||
|  |  | ||||||
| void ShortEventDescriptor::Parse() { | void ShortEventDescriptor::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    const descr_short_event *s; |    const descr_short_event *s; | ||||||
|    data.setPointerAndOffset<const descr_short_event>(s, offset); |    data.setPointerAndOffset<const descr_short_event>(s, offset); | ||||||
|    languageCode[0]=s->lang_code1; |    languageCode[0]=s->lang_code1; | ||||||
| @@ -38,7 +38,7 @@ int ExtendedEventDescriptor::getLastDescriptorNumber() { | |||||||
| } | } | ||||||
|  |  | ||||||
| void ExtendedEventDescriptor::Parse() { | void ExtendedEventDescriptor::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const descr_extended_event>(s, offset); |    data.setPointerAndOffset<const descr_extended_event>(s, offset); | ||||||
|    languageCode[0]=s->lang_code1; |    languageCode[0]=s->lang_code1; | ||||||
|    languageCode[1]=s->lang_code2; |    languageCode[1]=s->lang_code2; | ||||||
| @@ -51,7 +51,7 @@ void ExtendedEventDescriptor::Parse() { | |||||||
| } | } | ||||||
|  |  | ||||||
| void ExtendedEventDescriptor::Item::Parse() { | void ExtendedEventDescriptor::Item::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    const item_extended_event *first; |    const item_extended_event *first; | ||||||
|    data.setPointerAndOffset<const item_extended_event>(first, offset); |    data.setPointerAndOffset<const item_extended_event>(first, offset); | ||||||
|    itemDescription.setDataAndOffset(data+offset, first->item_description_length, offset); |    itemDescription.setDataAndOffset(data+offset, first->item_description_length, offset); | ||||||
| @@ -327,7 +327,7 @@ int CaDescriptor::getCaPid() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void CaDescriptor::Parse() { | void CaDescriptor::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const descr_ca>(s, offset); |    data.setPointerAndOffset<const descr_ca>(s, offset); | ||||||
|    privateData.assign(data.getData(offset), getLength()-offset); |    privateData.assign(data.getData(offset), getLength()-offset); | ||||||
| } | } | ||||||
| @@ -477,7 +477,7 @@ int ServiceDescriptor::getServiceType() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void ServiceDescriptor::Parse() { | void ServiceDescriptor::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const descr_service>(s, offset); |    data.setPointerAndOffset<const descr_service>(s, offset); | ||||||
|    providerName.setDataAndOffset(data+offset, s->provider_name_length, offset); |    providerName.setDataAndOffset(data+offset, s->provider_name_length, offset); | ||||||
|    const descr_service_mid *mid; |    const descr_service_mid *mid; | ||||||
| @@ -526,7 +526,7 @@ int ComponentDescriptor::getComponentTag() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void ComponentDescriptor::Parse() { | void ComponentDescriptor::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const descr_component>(s, offset); |    data.setPointerAndOffset<const descr_component>(s, offset); | ||||||
|    languageCode[0]=s->lang_code1; |    languageCode[0]=s->lang_code1; | ||||||
|    languageCode[1]=s->lang_code2; |    languageCode[1]=s->lang_code2; | ||||||
| @@ -580,7 +580,7 @@ int FrequencyListDescriptor::getCodingType() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void FrequencyListDescriptor::Parse() { | void FrequencyListDescriptor::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const descr_frequency_list>(s, offset); |    data.setPointerAndOffset<const descr_frequency_list>(s, offset); | ||||||
|    frequencies.setData(data+offset, getLength()-offset); |    frequencies.setData(data+offset, getLength()-offset); | ||||||
| } | } | ||||||
| @@ -594,7 +594,7 @@ void MultilingualNameDescriptor::Parse() { | |||||||
| } | } | ||||||
|  |  | ||||||
| void MultilingualNameDescriptor::Name::Parse() { | void MultilingualNameDescriptor::Name::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    const entry_multilingual_name *s; |    const entry_multilingual_name *s; | ||||||
|    data.setPointerAndOffset<const entry_multilingual_name>(s, offset); |    data.setPointerAndOffset<const entry_multilingual_name>(s, offset); | ||||||
|    languageCode[0]=s->lang_code1; |    languageCode[0]=s->lang_code1; | ||||||
| @@ -609,7 +609,7 @@ int MultilingualComponentDescriptor::getComponentTag() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void MultilingualComponentDescriptor::Parse() { | void MultilingualComponentDescriptor::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const descr_multilingual_component>(s, offset); |    data.setPointerAndOffset<const descr_multilingual_component>(s, offset); | ||||||
|    nameLoop.setData(data+sizeof(descr_multilingual_component), getLength()-sizeof(descr_multilingual_component)); |    nameLoop.setData(data+sizeof(descr_multilingual_component), getLength()-sizeof(descr_multilingual_component)); | ||||||
| } | } | ||||||
| @@ -619,7 +619,7 @@ void MultilingualServiceNameDescriptor::Parse() { | |||||||
| } | } | ||||||
|  |  | ||||||
| void MultilingualServiceNameDescriptor::Name::Parse() { | void MultilingualServiceNameDescriptor::Name::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    const entry_multilingual_name *s; |    const entry_multilingual_name *s; | ||||||
|    data.setPointerAndOffset<const entry_multilingual_name>(s, offset); |    data.setPointerAndOffset<const entry_multilingual_name>(s, offset); | ||||||
|    languageCode[0]=s->lang_code1; |    languageCode[0]=s->lang_code1; | ||||||
| @@ -633,7 +633,7 @@ void MultilingualServiceNameDescriptor::Name::Parse() { | |||||||
| } | } | ||||||
|  |  | ||||||
| void LinkageDescriptor::Parse() { | void LinkageDescriptor::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const descr_linkage>(s, offset); |    data.setPointerAndOffset<const descr_linkage>(s, offset); | ||||||
|    privateData.assign(data.getData(offset), getLength()-offset); |    privateData.assign(data.getData(offset), getLength()-offset); | ||||||
| } | } | ||||||
| @@ -682,7 +682,7 @@ AudioType ISO639LanguageDescriptor::Language::getAudioType() { | |||||||
| } | } | ||||||
|  |  | ||||||
| void PDCDescriptor::Parse() { | void PDCDescriptor::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const descr_pdc>(s, offset); |    data.setPointerAndOffset<const descr_pdc>(s, offset); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -731,7 +731,7 @@ int MHP_ApplicationDescriptor::getApplicationPriority() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void MHP_ApplicationDescriptor::Parse() { | void MHP_ApplicationDescriptor::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    const descr_application *dapp; |    const descr_application *dapp; | ||||||
|    data.setPointerAndOffset<const descr_application>(dapp, offset); |    data.setPointerAndOffset<const descr_application>(dapp, offset); | ||||||
|    profileLoop.setDataAndOffset(data+offset, dapp->application_profiles_length, offset); |    profileLoop.setDataAndOffset(data+offset, dapp->application_profiles_length, offset); | ||||||
| @@ -790,7 +790,7 @@ int MHP_TransportProtocolDescriptor::getComponentTag() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void MHP_TransportProtocolDescriptor::Parse() { | void MHP_TransportProtocolDescriptor::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const descr_transport_protocol>(s, offset); |    data.setPointerAndOffset<const descr_transport_protocol>(s, offset); | ||||||
|    if (getProtocolId() == ObjectCarousel) { |    if (getProtocolId() == ObjectCarousel) { | ||||||
|       const transport_via_oc *oc; |       const transport_via_oc *oc; | ||||||
| @@ -821,7 +821,7 @@ void MHP_DVBJApplicationDescriptor::ApplicationEntry::Parse() { | |||||||
| } | } | ||||||
|  |  | ||||||
| void MHP_DVBJApplicationLocationDescriptor::Parse() { | void MHP_DVBJApplicationLocationDescriptor::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    const descr_dvbj_application_location *first; |    const descr_dvbj_application_location *first; | ||||||
|    data.setPointerAndOffset<const descr_dvbj_application_location>(first, offset); |    data.setPointerAndOffset<const descr_dvbj_application_location>(first, offset); | ||||||
|    baseDirectory.setDataAndOffset(data+offset, first->base_directory_length, offset); |    baseDirectory.setDataAndOffset(data+offset, first->base_directory_length, offset); | ||||||
| @@ -836,7 +836,7 @@ int MHP_ApplicationIconsDescriptor::getIconFlags() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void MHP_ApplicationIconsDescriptor::Parse() { | void MHP_ApplicationIconsDescriptor::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    const descr_application_icons_descriptor *first; |    const descr_application_icons_descriptor *first; | ||||||
|    data.setPointerAndOffset<const descr_application_icons_descriptor>(first, offset); |    data.setPointerAndOffset<const descr_application_icons_descriptor>(first, offset); | ||||||
|    iconLocator.setDataAndOffset(data+offset, first->icon_locator_length, offset); |    iconLocator.setDataAndOffset(data+offset, first->icon_locator_length, offset); | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ | |||||||
|  *   the Free Software Foundation; either version 2 of the License, or     * |  *   the Free Software Foundation; either version 2 of the License, or     * | ||||||
|  *   (at your option) any later version.                                   * |  *   (at your option) any later version.                                   * | ||||||
|  *                                                                         * |  *                                                                         * | ||||||
|  *   $Id: section.c 1.3 2004/02/20 13:44:59 kls Exp $ |  *   $Id: section.c 1.4 2006/02/18 10:38:20 kls Exp $ | ||||||
|  *                                                                         * |  *                                                                         * | ||||||
|  ***************************************************************************/ |  ***************************************************************************/ | ||||||
|  |  | ||||||
| @@ -18,7 +18,7 @@ namespace SI { | |||||||
| /*********************** PAT ***********************/ | /*********************** PAT ***********************/ | ||||||
|  |  | ||||||
| void PAT::Parse() { | void PAT::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const pat>(s, offset); |    data.setPointerAndOffset<const pat>(s, offset); | ||||||
|    associationLoop.setData(data+offset, getLength()-offset-4); |    associationLoop.setData(data+offset, getLength()-offset-4); | ||||||
| } | } | ||||||
| @@ -48,7 +48,7 @@ void CAT::Parse() { | |||||||
| /*********************** PMT ***********************/ | /*********************** PMT ***********************/ | ||||||
|  |  | ||||||
| void PMT::Parse() { | void PMT::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const pmt>(s, offset); |    data.setPointerAndOffset<const pmt>(s, offset); | ||||||
|    commonDescriptors.setDataAndOffset(data+offset, HILO(s->program_info_length), offset); |    commonDescriptors.setDataAndOffset(data+offset, HILO(s->program_info_length), offset); | ||||||
|    streamLoop.setData(data+offset, getLength()-offset-4); |    streamLoop.setData(data+offset, getLength()-offset-4); | ||||||
| @@ -71,7 +71,7 @@ int PMT::Stream::getStreamType() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void PMT::Stream::Parse() { | void PMT::Stream::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const pmt_info>(s, offset); |    data.setPointerAndOffset<const pmt_info>(s, offset); | ||||||
|    streamDescriptors.setData(data+offset, HILO(s->ES_info_length)); |    streamDescriptors.setData(data+offset, HILO(s->ES_info_length)); | ||||||
| } | } | ||||||
| @@ -79,7 +79,7 @@ void PMT::Stream::Parse() { | |||||||
| /*********************** TSDT ***********************/ | /*********************** TSDT ***********************/ | ||||||
|  |  | ||||||
| void TSDT::Parse() { | void TSDT::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const tsdt>(s, offset); |    data.setPointerAndOffset<const tsdt>(s, offset); | ||||||
|    transportStreamDescriptors.setDataAndOffset(data+offset, getLength()-offset-4, offset); |    transportStreamDescriptors.setDataAndOffset(data+offset, getLength()-offset-4, offset); | ||||||
| } | } | ||||||
| @@ -91,7 +91,7 @@ int NIT::getNetworkId() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void NIT::Parse() { | void NIT::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const nit>(s, offset); |    data.setPointerAndOffset<const nit>(s, offset); | ||||||
|    commonDescriptors.setDataAndOffset(data+offset, HILO(s->network_descriptor_length), offset); |    commonDescriptors.setDataAndOffset(data+offset, HILO(s->network_descriptor_length), offset); | ||||||
|    const nit_mid *mid; |    const nit_mid *mid; | ||||||
| @@ -108,7 +108,7 @@ int NIT::TransportStream::getOriginalNetworkId() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void NIT::TransportStream::Parse() { | void NIT::TransportStream::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const ni_ts>(s, offset); |    data.setPointerAndOffset<const ni_ts>(s, offset); | ||||||
|    transportStreamDescriptors.setData(data+offset, HILO(s->transport_descriptors_length)); |    transportStreamDescriptors.setData(data+offset, HILO(s->transport_descriptors_length)); | ||||||
| } | } | ||||||
| @@ -116,7 +116,7 @@ void NIT::TransportStream::Parse() { | |||||||
| /*********************** SDT ***********************/ | /*********************** SDT ***********************/ | ||||||
|  |  | ||||||
| void SDT::Parse() { | void SDT::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const sdt>(s, offset); |    data.setPointerAndOffset<const sdt>(s, offset); | ||||||
|    serviceLoop.setData(data+offset, getLength()-offset-4); //4 is for CRC |    serviceLoop.setData(data+offset, getLength()-offset-4); //4 is for CRC | ||||||
| } | } | ||||||
| @@ -150,7 +150,7 @@ int SDT::Service::getFreeCaMode() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void SDT::Service::Parse() { | void SDT::Service::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const sdt_descr>(s, offset); |    data.setPointerAndOffset<const sdt_descr>(s, offset); | ||||||
|    serviceDescriptors.setData(data+offset, HILO(s->descriptors_loop_length)); |    serviceDescriptors.setData(data+offset, HILO(s->descriptors_loop_length)); | ||||||
| } | } | ||||||
| @@ -188,7 +188,7 @@ bool EIT::isActualTS() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void EIT::Parse() { | void EIT::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const eit>(s, offset); |    data.setPointerAndOffset<const eit>(s, offset); | ||||||
|    //printf("%d %d %d %d %d\n", getServiceId(), getTransportStreamId(), getOriginalNetworkId(), isPresentFollowing(), isActualTS()); |    //printf("%d %d %d %d %d\n", getServiceId(), getTransportStreamId(), getOriginalNetworkId(), isPresentFollowing(), isActualTS()); | ||||||
|    eventLoop.setData(data+offset, getLength()-offset-4); //4 is for CRC |    eventLoop.setData(data+offset, getLength()-offset-4); //4 is for CRC | ||||||
| @@ -243,7 +243,7 @@ int EIT::Event::getFreeCaMode() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void EIT::Event::Parse() { | void EIT::Event::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const eit_event>(s, offset); |    data.setPointerAndOffset<const eit_event>(s, offset); | ||||||
|    //printf("%d %d %d\n", getStartTime(), getDuration(), getRunningStatus()); |    //printf("%d %d %d\n", getStartTime(), getDuration(), getRunningStatus()); | ||||||
|    eventDescriptors.setData(data+offset, HILO(s->descriptors_loop_length)); |    eventDescriptors.setData(data+offset, HILO(s->descriptors_loop_length)); | ||||||
| @@ -266,7 +266,7 @@ time_t TOT::getTime() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void TOT::Parse() { | void TOT::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const tot>(s, offset); |    data.setPointerAndOffset<const tot>(s, offset); | ||||||
|    descriptorLoop.setData(data+offset, getLength()-offset-4); |    descriptorLoop.setData(data+offset, getLength()-offset-4); | ||||||
| } | } | ||||||
| @@ -274,7 +274,7 @@ void TOT::Parse() { | |||||||
| /*********************** RST ***********************/ | /*********************** RST ***********************/ | ||||||
|  |  | ||||||
| void RST::Parse() { | void RST::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    const rst *s; |    const rst *s; | ||||||
|    data.setPointerAndOffset<const rst>(s, offset); |    data.setPointerAndOffset<const rst>(s, offset); | ||||||
|    infoLoop.setData(data+offset, getLength()-offset); |    infoLoop.setData(data+offset, getLength()-offset); | ||||||
| @@ -315,7 +315,7 @@ int AIT::getAITVersion() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void AIT::Parse() { | void AIT::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const ait>(first, offset); |    data.setPointerAndOffset<const ait>(first, offset); | ||||||
|    commonDescriptors.setDataAndOffset(data+offset, HILO(first->common_descriptors_length), offset); |    commonDescriptors.setDataAndOffset(data+offset, HILO(first->common_descriptors_length), offset); | ||||||
|    const ait_mid *mid; |    const ait_mid *mid; | ||||||
| @@ -336,7 +336,7 @@ int AIT::Application::getControlCode() const { | |||||||
| } | } | ||||||
|  |  | ||||||
| void AIT::Application::Parse() { | void AIT::Application::Parse() { | ||||||
|    unsigned int offset=0; |    int offset=0; | ||||||
|    data.setPointerAndOffset<const ait_app>(s, offset); |    data.setPointerAndOffset<const ait_app>(s, offset); | ||||||
|    applicationDescriptors.setData(data+offset, HILO(s->application_descriptors_length)); |    applicationDescriptors.setData(data+offset, HILO(s->application_descriptors_length)); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ | |||||||
|  *   the Free Software Foundation; either version 2 of the License, or     * |  *   the Free Software Foundation; either version 2 of the License, or     * | ||||||
|  *   (at your option) any later version.                                   * |  *   (at your option) any later version.                                   * | ||||||
|  *                                                                         * |  *                                                                         * | ||||||
|  *   $Id: si.c 1.14 2005/05/28 14:11:16 kls Exp $ |  *   $Id: si.c 1.15 2006/02/18 10:38:20 kls Exp $ | ||||||
|  *                                                                         * |  *                                                                         * | ||||||
|  ***************************************************************************/ |  ***************************************************************************/ | ||||||
|  |  | ||||||
| @@ -22,7 +22,7 @@ Object::Object() { | |||||||
| Object::Object(CharArray &d) : data(d) { | Object::Object(CharArray &d) : data(d) { | ||||||
| } | } | ||||||
|  |  | ||||||
| void Object::setData(const unsigned char*d, unsigned int size, bool doCopy) { | void Object::setData(const unsigned char*d, int size, bool doCopy) { | ||||||
|    data.assign(d, size, doCopy); |    data.assign(d, size, doCopy); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -30,7 +30,7 @@ void Object::setData(CharArray &d) { | |||||||
|    data=d; |    data=d; | ||||||
| } | } | ||||||
|  |  | ||||||
| bool Object::checkSize(unsigned int offset) { | bool Object::checkSize(int offset) { | ||||||
|    return data.checkSize(offset); |    return data.checkSize(offset); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										10
									
								
								libsi/si.h
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								libsi/si.h
									
									
									
									
									
								
							| @@ -6,7 +6,7 @@ | |||||||
|  *   the Free Software Foundation; either version 2 of the License, or     * |  *   the Free Software Foundation; either version 2 of the License, or     * | ||||||
|  *   (at your option) any later version.                                   * |  *   (at your option) any later version.                                   * | ||||||
|  *                                                                         * |  *                                                                         * | ||||||
|  *   $Id: si.h 1.12 2005/09/03 15:19:00 kls Exp $ |  *   $Id: si.h 1.13 2006/02/18 10:38:20 kls Exp $ | ||||||
|  *                                                                         * |  *                                                                         * | ||||||
|  ***************************************************************************/ |  ***************************************************************************/ | ||||||
|  |  | ||||||
| @@ -184,7 +184,7 @@ public: | |||||||
|    Object(); |    Object(); | ||||||
|    Object(CharArray &d); |    Object(CharArray &d); | ||||||
|    //can only be called once since data is immutable |    //can only be called once since data is immutable | ||||||
|    void setData(const unsigned char*data, unsigned int size, bool doCopy=true); |    void setData(const unsigned char*data, int size, bool doCopy=true); | ||||||
|    CharArray getData() { return data; } |    CharArray getData() { return data; } | ||||||
|    //returns the valid flag which indicates if data is all right or errors have been encountered |    //returns the valid flag which indicates if data is all right or errors have been encountered | ||||||
|    bool isValid() { return data.isValid(); } |    bool isValid() { return data.isValid(); } | ||||||
| @@ -196,7 +196,7 @@ protected: | |||||||
|    void setData(CharArray &d); |    void setData(CharArray &d); | ||||||
|    //returns whether the given offset fits within the limits of the actual data |    //returns whether the given offset fits within the limits of the actual data | ||||||
|    //The valid flag will be set accordingly |    //The valid flag will be set accordingly | ||||||
|    bool checkSize(unsigned int offset); |    bool checkSize(int offset); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| class Section : public Object { | class Section : public Object { | ||||||
| @@ -242,7 +242,7 @@ public: | |||||||
|    //never forget to call this |    //never forget to call this | ||||||
|    void setData(CharArray d, int l) { Object::setData(d); checkSize(l); length=l; } |    void setData(CharArray d, int l) { Object::setData(d); checkSize(l); length=l; } | ||||||
|    //convenience method |    //convenience method | ||||||
|    void setDataAndOffset(CharArray d, int l, unsigned int &offset) { Object::setData(d); checkSize(l); length=l; offset+=l; } |    void setDataAndOffset(CharArray d, int l, int &offset) { Object::setData(d); checkSize(l); length=l; offset+=l; } | ||||||
|    virtual int getLength() { return length; } |    virtual int getLength() { return length; } | ||||||
| private: | private: | ||||||
|    int length; |    int length; | ||||||
| @@ -384,7 +384,7 @@ typedef uint64_t  SixtyFourBit; | |||||||
| template <typename T> class TypeLoop : public Loop { | template <typename T> class TypeLoop : public Loop { | ||||||
| public: | public: | ||||||
|    int getCount() { return getLength()/sizeof(T); } |    int getCount() { return getLength()/sizeof(T); } | ||||||
|    T operator[](const unsigned int index) const |    T operator[](const int index) const | ||||||
|       { |       { | ||||||
|          switch (sizeof(T)) { |          switch (sizeof(T)) { | ||||||
|          case 1: |          case 1: | ||||||
|   | |||||||
							
								
								
									
										14
									
								
								libsi/util.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								libsi/util.c
									
									
									
									
									
								
							| @@ -6,7 +6,7 @@ | |||||||
|  *   the Free Software Foundation; either version 2 of the License, or     * |  *   the Free Software Foundation; either version 2 of the License, or     * | ||||||
|  *   (at your option) any later version.                                   * |  *   (at your option) any later version.                                   * | ||||||
|  *                                                                         * |  *                                                                         * | ||||||
|  *   $Id: util.c 1.5 2005/05/28 14:15:29 kls Exp $ |  *   $Id: util.c 1.6 2006/02/18 10:38:20 kls Exp $ | ||||||
|  *                                                                         * |  *                                                                         * | ||||||
|  ***************************************************************************/ |  ***************************************************************************/ | ||||||
|  |  | ||||||
| @@ -47,7 +47,7 @@ CharArray& CharArray::operator=(const CharArray &f) { | |||||||
|     return *this; |     return *this; | ||||||
| } | } | ||||||
|  |  | ||||||
| void CharArray::assign(const unsigned char*data, unsigned int size, bool doCopy) { | void CharArray::assign(const unsigned char*data, int size, bool doCopy) { | ||||||
|     //immutable |     //immutable | ||||||
|     if (!data_) |     if (!data_) | ||||||
|       data_= doCopy ? (Data*)new DataOwnData() : (Data*)new DataForeignData(); |       data_= doCopy ? (Data*)new DataOwnData() : (Data*)new DataForeignData(); | ||||||
| @@ -76,13 +76,13 @@ bool CharArray::operator==(const CharArray &other) const { | |||||||
|       return false; |       return false; | ||||||
|  |  | ||||||
|    //do _not_ use strcmp! Data is not necessarily null-terminated. |    //do _not_ use strcmp! Data is not necessarily null-terminated. | ||||||
|    for (unsigned int i=0;i<data_->size;i++) |    for (int i=0;i<data_->size;i++) | ||||||
|       if (data_->data[i] != other.data_->data[i]) |       if (data_->data[i] != other.data_->data[i]) | ||||||
|          return false; |          return false; | ||||||
|    return true; |    return true; | ||||||
| } | } | ||||||
|  |  | ||||||
| CharArray CharArray::operator+(const unsigned int offset) const { | CharArray CharArray::operator+(const int offset) const { | ||||||
|    CharArray f(*this); |    CharArray f(*this); | ||||||
|    f.off+=offset; |    f.off+=offset; | ||||||
|    return f; |    return f; | ||||||
| @@ -117,7 +117,7 @@ CharArray::DataOwnData::~DataOwnData() { | |||||||
|    Delete(); |    Delete(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void CharArray::DataOwnData::assign(const unsigned char*d, unsigned int s) { | void CharArray::DataOwnData::assign(const unsigned char*d, int s) { | ||||||
|    Delete(); |    Delete(); | ||||||
|    size=s; |    size=s; | ||||||
|    unsigned char *newdata=new unsigned char[size]; |    unsigned char *newdata=new unsigned char[size]; | ||||||
| @@ -133,7 +133,7 @@ CharArray::DataForeignData::~DataForeignData() { | |||||||
|    Delete(); |    Delete(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void CharArray::DataForeignData::assign(const unsigned char*d, unsigned int s) { | void CharArray::DataForeignData::assign(const unsigned char*d, int s) { | ||||||
|    size=s; |    size=s; | ||||||
|    data=d; |    data=d; | ||||||
| } | } | ||||||
| @@ -143,7 +143,7 @@ void CharArray::DataForeignData::Delete() { | |||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
| void CharArray::Data::assign(unsigned int s) { | void CharArray::Data::assign(int s) { | ||||||
|    if (data) |    if (data) | ||||||
|       delete[] data; |       delete[] data; | ||||||
|    size=s; |    size=s; | ||||||
|   | |||||||
							
								
								
									
										34
									
								
								libsi/util.h
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								libsi/util.h
									
									
									
									
									
								
							| @@ -6,7 +6,7 @@ | |||||||
|  *   the Free Software Foundation; either version 2 of the License, or     * |  *   the Free Software Foundation; either version 2 of the License, or     * | ||||||
|  *   (at your option) any later version.                                   * |  *   (at your option) any later version.                                   * | ||||||
|  *                                                                         * |  *                                                                         * | ||||||
|  *   $Id: util.h 1.5 2004/10/23 14:22:40 kls Exp $ |  *   $Id: util.h 1.6 2006/02/18 10:38:20 kls Exp $ | ||||||
|  *                                                                         * |  *                                                                         * | ||||||
|  ***************************************************************************/ |  ***************************************************************************/ | ||||||
|  |  | ||||||
| @@ -37,14 +37,14 @@ public: | |||||||
|    ~CharArray(); |    ~CharArray(); | ||||||
|  |  | ||||||
|    //can be called exactly once |    //can be called exactly once | ||||||
|    void assign(const unsigned char*data, unsigned int size, bool doCopy=true); |    void assign(const unsigned char*data, int size, bool doCopy=true); | ||||||
|    //compares to a null-terminated string |    //compares to a null-terminated string | ||||||
|    bool operator==(const char *string) const; |    bool operator==(const char *string) const; | ||||||
|    //compares to another CharArray (data not necessarily null-terminated) |    //compares to another CharArray (data not necessarily null-terminated) | ||||||
|    bool operator==(const CharArray &other) const; |    bool operator==(const CharArray &other) const; | ||||||
|  |  | ||||||
|    //returns another CharArray with its offset incremented by offset |    //returns another CharArray with its offset incremented by offset | ||||||
|    CharArray operator+(const unsigned int offset) const; |    CharArray operator+(const int offset) const; | ||||||
|  |  | ||||||
|    //access and convenience methods |    //access and convenience methods | ||||||
|    const unsigned char* getData() const { return data_->data+off; } |    const unsigned char* getData() const { return data_->data+off; } | ||||||
| @@ -52,28 +52,28 @@ public: | |||||||
|    template <typename T> const T* getData() const { return (T*)(data_->data+off); } |    template <typename T> const T* getData() const { return (T*)(data_->data+off); } | ||||||
|    template <typename T> const T* getData(int offset) const { return (T*)(data_->data+offset+off); } |    template <typename T> const T* getData(int offset) const { return (T*)(data_->data+offset+off); } | ||||||
|       //sets p to point to data+offset, increments offset |       //sets p to point to data+offset, increments offset | ||||||
|    template <typename T> void setPointerAndOffset(const T* &p, unsigned int &offset) const { p=(T*)getData(offset); offset+=sizeof(T); } |    template <typename T> void setPointerAndOffset(const T* &p, int &offset) const { p=(T*)getData(offset); offset+=sizeof(T); } | ||||||
|    unsigned char operator[](const unsigned int index) const { return data_->data ? data_->data[off+index] : 0; } |    unsigned char operator[](const int index) const { return data_->data ? data_->data[off+index] : 0; } | ||||||
|    int getLength() const { return data_->size; } |    int getLength() const { return data_->size; } | ||||||
|    u_int16_t TwoBytes(const unsigned int index) const { return data_->data ? data_->TwoBytes(off+index) : 0; } |    u_int16_t TwoBytes(const int index) const { return data_->data ? data_->TwoBytes(off+index) : 0; } | ||||||
|    u_int32_t FourBytes(const unsigned int index) const { return data_->data ? data_->FourBytes(off+index) : 0; } |    u_int32_t FourBytes(const int index) const { return data_->data ? data_->FourBytes(off+index) : 0; } | ||||||
|  |  | ||||||
|    bool isValid() const { return data_->valid; } |    bool isValid() const { return data_->valid; } | ||||||
|    bool checkSize(unsigned int offset) { return (data_->valid && (data_->valid=(off+offset < data_->size))); } |    bool checkSize(int offset) { return (data_->valid && offset>=0 && (data_->valid=(off+offset < data_->size))); } | ||||||
|  |  | ||||||
|    void addOffset(unsigned int offset) { off+=offset; } |    void addOffset(int offset) { off+=offset; } | ||||||
| private: | private: | ||||||
|    class Data { |    class Data { | ||||||
|    public: |    public: | ||||||
|       Data(); |       Data(); | ||||||
|       virtual ~Data(); |       virtual ~Data(); | ||||||
|  |  | ||||||
|       virtual void assign(const unsigned char*data, unsigned int size) = 0; |       virtual void assign(const unsigned char*data, int size) = 0; | ||||||
|       virtual void Delete() = 0; |       virtual void Delete() = 0; | ||||||
|  |  | ||||||
|       u_int16_t TwoBytes(const unsigned int index) const |       u_int16_t TwoBytes(const int index) const | ||||||
|          { return (data[index] << 8) | data[index+1]; } |          { return (data[index] << 8) | data[index+1]; } | ||||||
|       u_int32_t FourBytes(const unsigned int index) const |       u_int32_t FourBytes(const int index) const | ||||||
|          { return (data[index] << 24) | (data[index+1] << 16) | (data[index+2] << 8) | data[index+3]; } |          { return (data[index] << 24) | (data[index+1] << 16) | (data[index+2] << 8) | data[index+3]; } | ||||||
|       /*#ifdef CHARARRAY_THREADSAFE |       /*#ifdef CHARARRAY_THREADSAFE | ||||||
|       void Lock(); |       void Lock(); | ||||||
| @@ -83,11 +83,11 @@ private: | |||||||
|       void Unlock() {} |       void Unlock() {} | ||||||
|       #endif |       #endif | ||||||
|       Data(const Data& d); |       Data(const Data& d); | ||||||
|       void assign(unsigned int size); |       void assign(int size); | ||||||
|       */ |       */ | ||||||
|  |  | ||||||
|       const unsigned char*data; |       const unsigned char*data; | ||||||
|       unsigned int size; |       int size; | ||||||
|  |  | ||||||
|       // count_ is the number of CharArray objects that point at this |       // count_ is the number of CharArray objects that point at this | ||||||
|       // count_ must be initialized to 1 by all constructors |       // count_ must be initialized to 1 by all constructors | ||||||
| @@ -106,18 +106,18 @@ private: | |||||||
|    public: |    public: | ||||||
|       DataOwnData() {} |       DataOwnData() {} | ||||||
|       virtual ~DataOwnData(); |       virtual ~DataOwnData(); | ||||||
|       virtual void assign(const unsigned char*data, unsigned int size); |       virtual void assign(const unsigned char*data, int size); | ||||||
|       virtual void Delete(); |       virtual void Delete(); | ||||||
|    }; |    }; | ||||||
|    class DataForeignData : public Data { |    class DataForeignData : public Data { | ||||||
|    public: |    public: | ||||||
|       DataForeignData() {} |       DataForeignData() {} | ||||||
|       virtual ~DataForeignData(); |       virtual ~DataForeignData(); | ||||||
|       virtual void assign(const unsigned char*data, unsigned int size); |       virtual void assign(const unsigned char*data, int size); | ||||||
|       virtual void Delete(); |       virtual void Delete(); | ||||||
|    }; |    }; | ||||||
|    Data* data_; |    Data* data_; | ||||||
|    unsigned int off; |    int off; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user