Sections 1233 and 1234 of the Internal Revenue Code provide that generally, the gain or loss attributable to the closing of short stock or option contract positions is considered capital gain or loss if the underlying property (in this case, stock) is a capital asset in the hands of the taxpayer.
Section 1211 of the Internal Revenue Code provides as a general rule that losses from sales or exchanges of capital assets shall be allowed ONLY TO THE EXTENT OF GAINS from such sales or exchanges.
My personal thoughts only -- not any tax analysis. Tax laws are very very complicated.