Skip to content

SMPTE-TT : Removed appearance of garbage value in color code.#620

Closed
saurabhshri wants to merge 1 commit intoCCExtractor:masterfrom
saurabhshri:patch-13
Closed

SMPTE-TT : Removed appearance of garbage value in color code.#620
saurabhshri wants to merge 1 commit intoCCExtractor:masterfrom
saurabhshri:patch-13

Conversation

@saurabhshri
Copy link
Copy Markdown
Member

Today we made Sample Platform's difference generator a little better and found out that for SMPTE-TT font color often contains garbage data.

color

When I added that font color support, I left color_code variable uninitialized and hence this garbage value. This hopefully fixes this.

@saurabhshri
Copy link
Copy Markdown
Member Author

Preview from Sample Platform (PR Fixes the issue):

color

@cfsmp3
Copy link
Copy Markdown
Contributor

cfsmp3 commented Jan 8, 2017

Instead of

*color_code = NULL;
strncat(color_code,(context->subline) + (temp_pointer - (context->subline) + 1),6); //obtained color code

Just use
strncpy
which doesn't care about existing data.

Also be aware that strncat (or strncpy) don't null terminate the destination string, so you need to do it yourself.

(context->subline) + (temp_pointer - (context->subline) + 1)

That's a weird thing to do. Why not just temp_pointer+1 ?

@cfsmp3 cfsmp3 closed this Jan 8, 2017
@saurabhshri
Copy link
Copy Markdown
Member Author

@cfsmp3 Earlier I too was using strncpy to implement this (here : 6c1ba95). But as you mentioned it doesn't null terminate the string, so to add it explicitly was a two steps or more( because strcat uses \0 to identify the end of string which is not present if strncpy is used).

Where else strncat does infact null terminates the string, as opposed to strncpy. This is why I used this.

And regarding (context->subline) + (temp_pointer - (context->subline) + 1), I actually used Find and Replace to replace a variabe used while debugging to (temp_pointer - (context->subline) + 1, hence this :P

I'll change it to temp_pointer+1.

Does it sound okay?

@cfsmp3
Copy link
Copy Markdown
Contributor

cfsmp3 commented Jan 10, 2017

Also do color_code[7] instead of * and then malloc... 7 bytes it's OK to get from the stack, no need to deal with dynamic alloc. You can even init that block to all 0s.

cfsmp3 pushed a commit that referenced this pull request Jan 11, 2017
Also polished and improved existing code. More details : #620
@saurabhshri saurabhshri deleted the patch-13 branch January 11, 2017 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants