#include " " 用于用户自定义头文件,编译器会在先在用户当前目录开始搜索,找不到的话编译器到编译工具规定的目录中寻找该头文件。例如#include"smtp.h" 也可以在子目录里,例如#include"mylib/smtp.h"
#include< > 用于格式来引用标准库的头文件,编译器会自动在编译器设置的目录里搜索。例如#include
CString s;
s.Format("%2d", num1);
but it generates the following error message when compiling:
d:\my documents\visual studio 2005\projects\pt24\pt24\expression.cpp(74) : error C2664: 'void ATL::CStringT
with
[
BaseType=wchar_t,
StringTraits=StrTraitMFC_DLL
]
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Your project is UNICODE enabled so CString format expects an UNICODE string instead of an ASCII one. You need to use the _T macro to create an UNICODE string: str.Format(_T("%2d"), 42); You can also change you project settings to use ASCII if you wish. Go to Project properties, Configuration Properties, General and you'll find an option named "Character Set". Change it to "Use Multi-Byte Character Set".
string insertQuery;
insertQuery="INSERT INTO TABLE_NAME VALUES(" + appNo + ", '"+work_county+"', '"+ssn+ "', TO_DATE('"+birth_date +"','DDMMYYYY'), '"+gender +"', '"+last_name+"','"+first_name+"', '"+middle_name + "' , 'A')";
|
INSERT INTO TABLE_NAME VALUES( 001,'China','0000000','TO_DATE('01051983','DDMMYY'), |
1.MSSQL: ISNULL()
语法
ISNULL ( check_expression , replacement_value ) AS Item1
参数
check_expression
将被检查是否为 NULL的表达式。check_expression 可以是任何类型的。
replacement_value
在 check_expression 为 NULL时将返回的表达式。replacement_value 必须与 check_expresssion 具有相同的类型。
返回类型
返回与 check_expression 相同的类型。
注释
如果 check_expression 不为 NULL,那么返回该表达式的值;否则返回 replacement_value。
2.Oracle: NVL()
语法
NVL(eExpression1, eExpression2)
参数
eExpression1, eExpression2
如果 eExpression1 的计算结果为 null 值,则 NVL() 返回 eExpression2。如果 eExpression1 的计算结果不是 null 值,则返回 eExpression1。eExpression1 和 eExpression2 可以是任意一种数据类型。如果 eExpression1 与 eExpression2 的结果皆为 null 值,则 NVL( ) 返回 NULL
返回值类型
字符型、日期型、日期时间型、数值型、货币型、逻辑型或 null 值
说明
在不支持 null 值或 null 值无关紧要的情况下,可以使用 NVL( ) 来移去计算或操作中的 null 值。
3.Mysql: IFNULL()
语法
IFNULL(expr1,expr2)
参数
expr1,expr2
假如expr1不是NULL,IFNULL()返回expr1,否则它返回expr2。IFNULL()返回一个数字或字符串值,取决于它被使用的上下文环境。Harry Hochheiser, hhochheiser@towson.edu
// buffer overflow demo
#include <>
using namespace std;
int main() {
int importantData = 1;
int buffer[10];
cout << "importantData = " << importantData << endl;
cout << "buffer overflow " << endl;v
for (int i = 0; i < ??; i++)
buffer[i] = 7;
cout << "importantData = " << importantData << endl;
return 0;
}
The following security checklist is a tool used to find potential security vulnerabilities in your programs. Read the checklist, apply it (as best you can) to the problem given above, and answer these questions:
Some of the elements in the checklist may refer to material that we have not seen this semester. If so, please disregard them.
Please submit the program with appropriate marking (in color or alternate font) and your answers to these questions
Security checklist | ||||
Vulnerability | Buffer Overflow | |||
Description | A buffer overflow occurs when data is written beyond the boundaries of a fixed length buffer overwriting adjacent memory locations which may include other buffers, variables and program flow data. | |||
Risk | Writing outside the bounds of a block of allocated memory can corrupt data, crash the program, or cause the execution of malicious code.WARNING: over 80% of security problems result from buffer overflows! | |||
Real World Exaple | The earliest known exploitation of a buffer overflow was the Morris worm in 1988. In 2001, the Code Red wormexploited a buffer overflow in Microsoft's Internet Information Services and in 2003 the SQLSlammer worm compromised machines running Microsoft SQL Server 2000. |
Task: Check your code | Yes | No | Unsure | |
1. Check each array assignment that could result in an overflow (indices >= ARR_SIZE ) EX: arr[ARR_SIZE] = 0; | ||||
2.Check loop boundaries >= ARR_SIZE EX: for (i = 0; i <= ARR_SIZE; i++) array[i] = x;//off-by-one! | ||||
3. Check all indices that are input. EX: cin >> i; array[i] = x; | ||||
4. Are all string functions within range? (hint: do not use: gets, strcpy, sprintf) | ||||
5.Are arrays close to pointers? (Hint: remember the return address of a function is a pointer) | ||||
Shaded area indicated this is a high security risk! |