microsoft/Windows-classic-samples

[Win7Sample.OleDb.RowsetViewer] Writing LONG data in SHORT variable

dmitry-lipetsk opened this issue · 0 comments

VS Debugger found a problem with the following code:

DBTYPE wSchemaType;
if(ConvertToLONG(pwszValue, (LONG*)&wSchemaType, 0/*Min*/, LONG_MAX, 0/*Base*/))

DBTYPE is based on USHORT datatype.

I have not got any problems with this code within 20 years but I think it needs to correct it with:

				LONG lSchemaType; /*DBTYPE == UI2*/
				if(ConvertToLONG(pwszValue, &lSchemaType, 0/*Min*/, USHRT_MAX, 0/*Base*/))
				{
					//NOTE: on failure we have no choice to leave the column as the original
					//returned integer.
					StringCopy(pwszValue, GetDBTypeName((DBTYPE)lSchemaType), ulMaxSize);
				}

I tested this new code under debugger - it works fine.