From 1107496d3c3dd1c7398bb3ccdc92df610e5ae61a Mon Sep 17 00:00:00 2001 From: Dustin Oprea Date: Mon, 23 Apr 2018 21:59:42 -0400 Subject: [PATCH] ifd_builder: AddChildIb now validates not previously added. --- ifd_builder.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ifd_builder.go b/ifd_builder.go index 8ecfd04..b21908e 100644 --- a/ifd_builder.go +++ b/ifd_builder.go @@ -21,7 +21,6 @@ var ( // TODO(dustin): !! Make sure we either replace existing IFDs or validate that the IFD doesn't already exist. -// TODO(dustin): !! Add test for NewIfdBuilderWithExistingIfd. type builderTag struct { @@ -573,6 +572,7 @@ func (ib *IfdBuilder) Add(bt builderTag) (err error) { return nil } +// AddChildIb adds a tag that branches to a new IFD. func (ib *IfdBuilder) AddChildIb(childIb *IfdBuilder) (err error) { defer func() { if state := recover(); state != nil { @@ -586,6 +586,15 @@ func (ib *IfdBuilder) AddChildIb(childIb *IfdBuilder) (err error) { log.Panicf("Child IFD does not have the same byte-order: [%s] != [%s]", childIb.byteOrder, ib.byteOrder) } + // Since no standard IFDs supports occuring more than once, check that a + // tag of this type has not been previously added. Note that we just search + // the current IFD and *not every* IFD. + for _, bt := range childIb.tags { + if bt.tagId == childIb.ifdTagId { + log.Panicf("child-IFD previously added: [%s]", childIb.ifdName) + } + } + bt := builderTag{ ifdName: childIb.ifdName, tagId: childIb.ifdTagId,