Closed
Bug 514136
Opened 15 years ago
Closed 11 years ago
Increase the size of the char array for imap command tag
Categories
(MailNews Core :: Networking: IMAP, defect)
Tracking
(Not tracked)
RESOLVED
FIXED
Thunderbird 22.0
People
(Reporter: Usul, Assigned: aceman)
References
()
Details
Attachments
(1 file, 2 obsolete files)
1.84 KB,
patch
|
aceman
:
review+
|
Details | Diff | Splinter Review |
the first imap one is safe as long as we don't send more than 1 billion commands to the imap server (though it should be fixed to use nsCString)
Flags: wanted-thunderbird3?
Updated•15 years ago
|
Summary: Use nsCString instead of a table in urled email → Use nsCString instead of char array for imap command tag
Reporter | ||
Updated•11 years ago
|
Flags: wanted-thunderbird3?
This line number also seems to be outdated. Which function is meant? Also, do we need to care about billion commands? My IMAP server rejects uploading even 100 messages (supposedly rate limiting) :)
Reporter | ||
Comment 2•11 years ago
|
||
(In reply to :aceman from comment #1) > This line number also seems to be outdated. Which function is meant? > > Also, do we need to care about billion commands? My IMAP server rejects > uploading even 100 messages (supposedly rate limiting) :) Neil ?
Comment 3•11 years ago
|
||
It's IncrementCommandTagNumber(), and it's unrelated to the number of messages. Also, the code won't actually overflow, as due to alignment requirements, there's actually 12 characters of space allocated to that 32-bit number ;-)
But can we rely on that? The code is: char m_currentServerCommandTag[10]; // enough for a billion int m_currentServerCommandTagNumber; So if int is 32-bit long, the number 2147483648 is 10 chars long and the trailing \0 has no space. So do we increase it to 11 (if there is alignment, we will lose no additional memory)?
Comment 5•11 years ago
|
||
The point is that the compiler will generate identical code for 9, 10, 11 or 12 because it has to round the array up to 12 anyway. Only code that explicitly checks the array length (via sizeof or templates) would know the difference.
Comment 6•11 years ago
|
||
Also the code uses %ld so you'd actually see -2147483648 ;-)
So use nsCString.AppendInt() as the description requests and be done with it? :) Is the function speed sensitive?
Comment 8•11 years ago
|
||
No, nsCString would be overkill.
Then why do you oppose char[11] so that is it obvious to anyone and does not increase memory usage?
Comment 10•11 years ago
|
||
(In reply to aceman from comment #9) > Then why do you oppose char[11] so that is it obvious to anyone and does not > increase memory usage? It was not my intent to oppose it; I was merely correcting your example which was using a number that probably does not fit in an int (are there platforms with 64-bit ints? why is that an int, and then cast to a long for the sprintf?)
Assignee | ||
Comment 11•11 years ago
|
||
Comment 12•11 years ago
|
||
Comment on attachment 725808 [details] [diff] [review] patch >+ sprintf(m_currentServerCommandTag,"%d", ++m_currentServerCommandTagNumber); Nit: while you're editing this, space after the first comma please. >+ // 11 = enough memory for the decimal representation of MAX_INT + trailing nul >+ char m_currentServerCommandTag[11]; I guess after you reach MAX_INT, ++m_currentServerCommandTagNumber becomes undefined behaviour. > int m_currentServerCommandTagNumber; Maybe we should switch to uint32_t to avoid the problem ;-)
Attachment #725808 -
Flags: review?(neil) → review+
Updated•11 years ago
|
Summary: Use nsCString instead of char array for imap command tag → Increase the size of the char array for imap command tag
Assignee | ||
Comment 13•11 years ago
|
||
(In reply to neil@parkwaycc.co.uk from comment #12) > Comment on attachment 725808 [details] [diff] [review] > patch > > >+ sprintf(m_currentServerCommandTag,"%d", ++m_currentServerCommandTagNumber); > Nit: while you're editing this, space after the first comma please. > > >+ // 11 = enough memory for the decimal representation of MAX_INT + trailing nul > >+ char m_currentServerCommandTag[11]; > I guess after you reach MAX_INT, ++m_currentServerCommandTagNumber becomes > undefined behaviour. Yes, but that is a different problem:) > > int m_currentServerCommandTagNumber; > Maybe we should switch to uint32_t to avoid the problem ;-) I thought about that, but then how do we guarantee "%d" is 32 bit? I'd imagine that int and "%d" would mathc in size on all archs/compilers. But I do not know if uin32_t and "%d" always match.
Comment 14•11 years ago
|
||
That's easy; even on ILP64, uint32_t gets promoted to unsigned int.
Assignee | ||
Comment 15•11 years ago
|
||
Attachment #725808 -
Attachment is obsolete: true
Attachment #725873 -
Flags: review?(neil)
Comment 16•11 years ago
|
||
Comment on attachment 725873 [details] [diff] [review] patch v2 >+ sprintf(m_currentServerCommandTag, "%d", ++m_currentServerCommandTagNumber); I guess this needs to be %u now... r=me with that fixed.
Attachment #725873 -
Flags: review?(neil) → review+
Assignee | ||
Comment 17•11 years ago
|
||
Thanks.
Attachment #725873 -
Attachment is obsolete: true
Attachment #725935 -
Flags: review+
Keywords: checkin-needed
Comment 18•11 years ago
|
||
https://hg.mozilla.org/comm-central/rev/5fa1d0a57bcb
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Target Milestone: --- → Thunderbird 22.0
You need to log in
before you can comment on or make changes to this bug.
Description
•