mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-01-23 12:44:09 +01:00
doc: Prefer !var over var == NULL checks
This commit is contained in:
parent
54b0b7d9e9
commit
3cb432a81c
@ -19,6 +19,7 @@ Besides the kernel coding style above, oFono has special flavors for its own.
|
|||||||
Some of them are mandatory (marked as 'M'), while some others are optional
|
Some of them are mandatory (marked as 'M'), while some others are optional
|
||||||
(marked as 'O'), but generally preferred.
|
(marked as 'O'), but generally preferred.
|
||||||
|
|
||||||
|
|
||||||
M1: Blank line before and after an if/while/do/for statement
|
M1: Blank line before and after an if/while/do/for statement
|
||||||
============================================================
|
============================================================
|
||||||
There should be a blank line before if statement unless the if is nested and
|
There should be a blank line before if statement unless the if is nested and
|
||||||
@ -51,7 +52,7 @@ b = 3;
|
|||||||
|
|
||||||
The only exception to this rule applies when a variable is being allocated:
|
The only exception to this rule applies when a variable is being allocated:
|
||||||
array = g_try_new0(int, 20);
|
array = g_try_new0(int, 20);
|
||||||
if (array == NULL) // Correct
|
if (array) // Correct
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
@ -127,6 +128,7 @@ gboolean sim_ust_is_available(unsigned char *service_ust, unsigned char len,
|
|||||||
enum sim_ust_service index);
|
enum sim_ust_service index);
|
||||||
// better
|
// better
|
||||||
|
|
||||||
|
|
||||||
M5: Git commit message 50/72 formatting
|
M5: Git commit message 50/72 formatting
|
||||||
=======================================
|
=======================================
|
||||||
The commit message header should be within 50 characters. And if you have
|
The commit message header should be within 50 characters. And if you have
|
||||||
@ -186,7 +188,6 @@ must not contain include guards.
|
|||||||
|
|
||||||
M11: Naming of enums
|
M11: Naming of enums
|
||||||
====================
|
====================
|
||||||
|
|
||||||
Enums must have a descriptive name. The enum type should be small caps and
|
Enums must have a descriptive name. The enum type should be small caps and
|
||||||
it should not be typedef-ed. Enum contents should be in CAPITAL letters and
|
it should not be typedef-ed. Enum contents should be in CAPITAL letters and
|
||||||
prefixed by the enum type name.
|
prefixed by the enum type name.
|
||||||
@ -208,6 +209,7 @@ enum animal_type {
|
|||||||
ANIMAL_TYPE_TWO_LEGS = 2,
|
ANIMAL_TYPE_TWO_LEGS = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
M12: Enum as switch variable
|
M12: Enum as switch variable
|
||||||
====================
|
====================
|
||||||
|
|
||||||
@ -244,25 +246,21 @@ However if the enum comes from an external header file outside ofono
|
|||||||
we cannot make any assumption of how the enum is defined and this
|
we cannot make any assumption of how the enum is defined and this
|
||||||
rule might not apply.
|
rule might not apply.
|
||||||
|
|
||||||
|
|
||||||
M13: Check for pointer being NULL
|
M13: Check for pointer being NULL
|
||||||
=================================
|
=================================
|
||||||
|
When checking if a pointer or a return value is NULL, use the shorter check
|
||||||
When checking if a pointer or a return value is NULL, explicitly compare to
|
with "!" operator rather than explicitly compare to NULL.
|
||||||
NULL rather than use the shorter check with "!" operator.
|
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
1)
|
1)
|
||||||
array = g_try_new0(int, 20);
|
array = g_try_new0(int, 20);
|
||||||
if (!array) // Wrong
|
if (!array) // Correct
|
||||||
return;
|
return;
|
||||||
|
|
||||||
2)
|
2)
|
||||||
if (!g_at_chat_get_slave(chat)) // Wrong
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
3)
|
|
||||||
array = g_try_new0(int, 20);
|
array = g_try_new0(int, 20);
|
||||||
if (array == NULL) // Correct
|
if (array == NULL) // Wrong
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
@ -294,6 +292,7 @@ void foo() // Wrong
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
M16: Don't use hex value with shift operators
|
M16: Don't use hex value with shift operators
|
||||||
==============================================
|
==============================================
|
||||||
The expression argument to the shift operators should not be in hex.
|
The expression argument to the shift operators should not be in hex.
|
||||||
@ -306,6 +305,7 @@ Example:
|
|||||||
2)
|
2)
|
||||||
0x1 << y // Wrong
|
0x1 << y // Wrong
|
||||||
|
|
||||||
|
|
||||||
O1: Shorten the name
|
O1: Shorten the name
|
||||||
====================
|
====================
|
||||||
Better to use abbreviation, rather than full name, to name a variable,
|
Better to use abbreviation, rather than full name, to name a variable,
|
||||||
|
Loading…
Reference in New Issue
Block a user