Skip to content
Snippets Groups Projects
Commit b4f8e2e2 authored by Jonathan Schöbel's avatar Jonathan Schöbel
Browse files

Attr: added unsafe constructor

As usual it should be also possible to bypass calls to strdup, while
also taking care.
parent a0bb5928
No related branches found
No related tags found
No related merge requests found
......@@ -43,8 +43,8 @@ FILE_NAME_10=2022;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp
FILE_NAME_11=2558;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ffragment_class.c;0;8
FILE_NAME_12=2167;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.c;0;8
FILE_NAME_13=5930;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.h;0;8
FILE_NAME_14=993;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.c;0;8
FILE_NAME_15=1225;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.h;0;8
FILE_NAME_14=1840;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.c;0;8
FILE_NAME_15=1605;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.h;0;8
FILE_NAME_16=25820;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext.c;0;8
FILE_NAME_17=904;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext.h;0;8
FILE_NAME_18=1779;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator.c;0;8
......@@ -59,7 +59,7 @@ FILE_NAME_26=533;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2
FILE_NAME_27=1085;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_cms.c;0;8
FILE_NAME_28=3283;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_data.c;0;8
FILE_NAME_29=8770;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8
FILE_NAME_30=1768;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8
FILE_NAME_30=4431;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8
FILE_NAME_31=11068;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text.c;0;8
FILE_NAME_32=5744;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8
FILE_NAME_33=165;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8
......
......@@ -86,6 +86,32 @@ SH_Attr_new (const char * name,
return attr;
}
/*@null@*/
/*@only@*/
struct SH_Attr *
SH_Attr_raw_new (/*@only@*/ char * name,
/*@null@*/ /*@only@*/ char * value,
/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/
{
struct SH_Attr * attr;
attr = malloc (sizeof (struct SH_Attr));
if (attr == NULL)
{
set_status (status, E_ALLOC, 4, "malloc failed");
return NULL;
}
attr->name = name;
attr->value = value;
set_success (status);
return attr;
}
void
SH_Attr_free (/*@only@*/ struct SH_Attr * attr)
/*@modifies attr->name@*/
......
......@@ -47,6 +47,16 @@ SH_Attr_new (const char * name,
/*@modifies fileSystem@*/
/*@modifies status@*/;
/*@null@*/
/*@only@*/
struct SH_Attr *
SH_Attr_raw_new (/*@only@*/ char * name,
/*@null@*/ /*@only@*/ char * value,
/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/;
void
SH_Attr_free (/*@only@*/ SH_Attr * attr)
/*@modifies attr@*/
......
......@@ -100,6 +100,70 @@ START_TEST(test_attr2_with_status)
}
END_TEST
START_TEST(test_attr_raw1_no_status)
{
struct SH_Attr * attr;
char * name = strdup ("name");
attr = SH_Attr_raw_new (name, NULL, NULL);
ck_assert_ptr_ne (NULL, attr);
ck_assert_ptr_eq (name, attr->name);
ck_assert_ptr_eq (NULL, attr->value);
SH_Attr_free (attr);
}
END_TEST
START_TEST(test_attr_raw1_with_status)
{
struct SH_Status status;
struct SH_Attr * attr;
char * name = strdup ("name");
_status_preinit (status);
attr = SH_Attr_raw_new (name, NULL, &status);
ck_assert_ptr_ne (NULL, attr);
ck_assert (succeed (&status));
ck_assert_ptr_eq (name, attr->name);
ck_assert_ptr_eq (NULL, attr->value);
SH_Attr_free (attr);
}
END_TEST
START_TEST(test_attr_raw2_no_status)
{
struct SH_Attr * attr;
char * name = strdup ("name");
char * value = strdup ("value");
attr = SH_Attr_raw_new (name, value, NULL);
ck_assert_ptr_ne (NULL, attr);
ck_assert_ptr_eq (name, attr->name);
ck_assert_ptr_eq (value, attr->value);
SH_Attr_free (attr);
}
END_TEST
START_TEST(test_attr_raw2_with_status)
{
struct SH_Status status;
struct SH_Attr * attr;
char * name = strdup ("name");
char * value = strdup ("value");
_status_preinit (status);
attr = SH_Attr_raw_new (name, value, &status);
ck_assert_ptr_ne (NULL, attr);
ck_assert (succeed (&status));
ck_assert_ptr_eq (name, attr->name);
ck_assert_ptr_eq (value, attr->value);
SH_Attr_free (attr);
}
END_TEST
Suite * test_suite (void)
{
Suite *s;
......@@ -114,6 +178,11 @@ Suite * test_suite (void)
tcase_add_test (tc_core, test_attr1_with_status);
tcase_add_test (tc_core, test_attr2_no_status);
tcase_add_test (tc_core, test_attr2_with_status);
tcase_add_test (tc_core, test_attr_raw1_no_status);
tcase_add_test (tc_core, test_attr_raw1_with_status);
tcase_add_test (tc_core, test_attr_raw2_no_status);
tcase_add_test (tc_core, test_attr_raw2_with_status);
suite_add_tcase (s, tc_core);
return s;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment