From 8ce0f8c6b5ef09c9320a1739a38784a76b3e8c30 Mon Sep 17 00:00:00 2001
From: acanas
Date: Mon, 15 Feb 2021 16:25:55 +0100
Subject: [PATCH] Version 20.31: Feb 15, 2021 Code refactoring in copy,
concat and sprintf.
---
swad_API.c | 343 ++++++++++++-----------------
swad_ID.c | 28 +--
swad_MFU.c | 21 +-
swad_RSS.c | 19 +-
swad_account.c | 72 +++----
swad_action.c | 5 +-
swad_agenda.c | 60 +++---
swad_announcement.c | 12 +-
swad_assignment.c | 34 ++-
swad_attendance.c | 46 ++--
swad_banner.c | 36 ++--
swad_box.c | 4 +-
swad_building.c | 29 +--
swad_calendar.c | 4 +-
swad_centre.c | 38 ++--
swad_centre_config.c | 42 ++--
swad_changelog.h | 3 +-
swad_chat.c | 155 +++++--------
swad_config.c | 2 +-
swad_connected.c | 7 +-
swad_country.c | 133 ++++--------
swad_country_config.c | 7 +-
swad_course.c | 36 ++--
swad_cryptography.c | 3 +-
swad_database.c | 3 +-
swad_date.c | 20 +-
swad_degree.c | 36 ++--
swad_degree_config.c | 2 +-
swad_degree_type.c | 16 +-
swad_department.c | 39 ++--
swad_duplicate.c | 10 +-
swad_enrolment.c | 20 +-
swad_exam.c | 11 +-
swad_exam_announcement.c | 46 ++--
swad_exam_log.c | 17 +-
swad_exam_print.c | 38 ++--
swad_exam_result.c | 11 +-
swad_exam_session.c | 7 +-
swad_exam_set.c | 30 +--
swad_figure.c | 48 ++---
swad_file.c | 58 ++---
swad_file_browser.c | 407 +++++++++++++----------------------
swad_follow.c | 22 +-
swad_form.c | 20 +-
swad_forum.c | 88 +++-----
swad_game.c | 17 +-
swad_global.c | 12 +-
swad_group.c | 116 +++++-----
swad_hierarchy.c | 9 +-
swad_holiday.c | 24 +--
swad_icon.c | 12 +-
swad_info.c | 66 ++----
swad_institution.c | 49 ++---
swad_institution_config.c | 3 +-
swad_layout.c | 2 +-
swad_link.c | 44 ++--
swad_log.c | 5 +-
swad_logo.c | 69 +++---
swad_mail.c | 65 ++----
swad_mark.c | 36 ++--
swad_match.c | 23 +-
swad_match_result.c | 11 +-
swad_media.c | 194 +++++++----------
swad_media.h | 8 +-
swad_message.c | 65 +++---
swad_network.c | 21 +-
swad_nickname.c | 104 ++++-----
swad_nickname.h | 2 +-
swad_notice.c | 23 +-
swad_notification.c | 6 +-
swad_pagination.c | 12 +-
swad_parameter.c | 42 ++--
swad_password.c | 14 +-
swad_photo.c | 96 +++------
swad_place.c | 43 ++--
swad_plugin.c | 89 +++-----
swad_profile.c | 36 ++--
swad_profile.h | 2 +-
swad_program.c | 19 +-
swad_project.c | 44 ++--
swad_record.c | 82 +++----
swad_report.c | 24 +--
swad_room.c | 44 ++--
swad_search.c | 27 +--
swad_session.c | 12 +-
swad_setting.c | 3 +-
swad_statistic.c | 110 ++++------
swad_string.c | 39 ++--
swad_survey.c | 48 ++---
swad_syllabus.c | 30 +--
swad_syllabus.h | 2 +-
swad_test.c | 186 ++++++----------
swad_test_import.c | 20 +-
swad_test_print.c | 38 ++--
swad_test_visibility.c | 2 +-
swad_theme.c | 15 +-
swad_timeline.c | 4 +-
swad_timeline_comment.c | 10 +-
swad_timeline_note.c | 8 +-
swad_timeline_note.h | 2 +-
swad_timeline_notification.c | 24 +--
swad_timeline_post.c | 3 +-
swad_timeline_publication.c | 14 +-
swad_timeline_user.c | 3 +-
swad_timetable.c | 17 +-
swad_user.c | 292 ++++++++++---------------
swad_user.h | 8 +-
swad_xml.c | 14 +-
swad_zip.c | 89 +++-----
109 files changed, 1770 insertions(+), 2871 deletions(-)
diff --git a/swad_API.c b/swad_API.c
index d40404eb..806713c9 100644
--- a/swad_API.c
+++ b/swad_API.c
@@ -225,8 +225,8 @@ static int API_RemoveOldWSKeys (struct soap *soap);
static int API_GetCurrentDegCodFromCurrentCrsCod (void);
static bool API_GetSomeUsrDataFromUsrCod (struct UsrData *UsrDat,long CrsCod);
-static int API_CheckParamsNewAccount (char *NewNicknameWithArroba, // Input
- char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1], // Output
+static int API_CheckParamsNewAccount (char *NewNickWithArroba, // Input
+ char NewNickWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1], // Output
char *NewEmail, // Input-output
char *NewPlainPassword, // Input
char *NewEncryptedPassword); // Output
@@ -531,8 +531,7 @@ static int API_GenerateNewWSKey (struct soap *soap,
return ReturnCode;
/***** Create a unique name for the key *****/
- Str_Copy (WSKey,Gbl.UniqueNameEncrypted,
- API_BYTES_WS_KEY);
+ Str_Copy (WSKey,Gbl.UniqueNameEncrypted,API_BYTES_WS_KEY);
/***** Check that key does not exist in database *****/
if (DB_QueryCOUNT ("can not get existence of key",
@@ -629,16 +628,12 @@ static bool API_GetSomeUsrDataFromUsrCod (struct UsrData *UsrDat,long CrsCod)
row = mysql_fetch_row (mysql_res);
/* Get user's name */
- Str_Copy (UsrDat->Surname1,row[0],
- Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
- Str_Copy (UsrDat->Surname2,row[1],
- Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
- Str_Copy (UsrDat->FirstName,row[2],
- Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
+ Str_Copy (UsrDat->Surname1,row[0],sizeof (UsrDat->Surname1) - 1);
+ Str_Copy (UsrDat->Surname2,row[1],sizeof (UsrDat->Surname2) - 1);
+ Str_Copy (UsrDat->FrstName,row[2],sizeof (UsrDat->FrstName) - 1);
/* Get user's photo */
- Str_Copy (UsrDat->Photo,row[3],
- Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
+ Str_Copy (UsrDat->Photo ,row[3],sizeof (UsrDat->Photo ) - 1);
/* Get user's brithday */
Dat_GetDateFromYYYYMMDD (&(UsrDat->Birthday),row[4]);
@@ -739,7 +734,7 @@ int swad__createAccount (struct soap *soap,
char *userNickname,char *userEmail,char *userPassword,char *appKey, // input
struct swad__createAccountOutput *createAccountOut) // output
{
- char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
+ char NewNickWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
char NewEncryptedPassword[Pwd_BYTES_ENCRYPTED_PASSWORD + 1];
int Result;
int ReturnCode;
@@ -761,7 +756,7 @@ int swad__createAccount (struct soap *soap,
/***** Check parameters used to create the new account *****/
Result = API_CheckParamsNewAccount (userNickname, // Input
- NewNicknameWithoutArroba,// Output
+ NewNickWithoutArroba,// Output
userEmail, // Input-output
userPassword, // Input
NewEncryptedPassword); // Output
@@ -777,23 +772,23 @@ int swad__createAccount (struct soap *soap,
/***** Set password to the password typed by the user *****/
Str_Copy (Gbl.Usrs.Me.UsrDat.Password,NewEncryptedPassword,
- Pwd_BYTES_ENCRYPTED_PASSWORD);
+ sizeof (Gbl.Usrs.Me.UsrDat.Password) - 1);
/***** User does not exist in the platform, so create him/her! *****/
Acc_CreateNewUsr (&Gbl.Usrs.Me.UsrDat,
true); // I am creating my own account
/***** Save nickname *****/
- Nck_UpdateNickInDB (Gbl.Usrs.Me.UsrDat.UsrCod,NewNicknameWithoutArroba);
- Str_Copy (Gbl.Usrs.Me.UsrDat.Nickname,NewNicknameWithoutArroba,
- Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA);
+ Nck_UpdateNickInDB (Gbl.Usrs.Me.UsrDat.UsrCod,NewNickWithoutArroba);
+ Str_Copy (Gbl.Usrs.Me.UsrDat.Nickname,NewNickWithoutArroba,
+ sizeof (Gbl.Usrs.Me.UsrDat.Nickname) - 1);
/***** Save email *****/
if (Mai_UpdateEmailInDB (&Gbl.Usrs.Me.UsrDat,userEmail))
{
/* Email updated sucessfully */
Str_Copy (Gbl.Usrs.Me.UsrDat.Email,userEmail,
- Cns_MAX_BYTES_EMAIL_ADDRESS);
+ sizeof (Gbl.Usrs.Me.UsrDat.Email) - 1);
Gbl.Usrs.Me.UsrDat.EmailConfirmed = false;
}
@@ -811,26 +806,26 @@ int swad__createAccount (struct soap *soap,
/*****************************************************************************/
// Return false on error
//char *userNickname,char *userEmail,char *userID,char *userPassword
-static int API_CheckParamsNewAccount (char *NewNicknameWithArroba, // Input
- char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1], // Output
+static int API_CheckParamsNewAccount (char *NewNickWithArroba, // Input
+ char NewNickWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1], // Output
char *NewEmail, // Input-output
char *NewPlainPassword, // Input
char *NewEncryptedPassword) // Output
{
/***** Step 1/3: Check new nickname *****/
/* Make a copy without possible starting arrobas */
- Str_Copy (NewNicknameWithoutArroba,NewNicknameWithArroba,
+ Str_Copy (NewNickWithoutArroba,NewNickWithArroba,
Nck_MAX_BYTES_NICKNAME_FROM_FORM);
- if (Nck_CheckIfNickWithArrobaIsValid (NewNicknameWithArroba)) // If new nickname is valid
+ if (Nck_CheckIfNickWithArrobaIsValid (NewNickWithArroba)) // If new nickname is valid
{
/***** Remove arrobas at the beginning *****/
- Str_RemoveLeadingArrobas (NewNicknameWithoutArroba);
+ Str_RemoveLeadingArrobas (NewNickWithoutArroba);
/***** Check if the new nickname matches any of the nicknames of other users *****/
if (DB_QueryCOUNT ("can not check if nickname already existed",
"SELECT COUNT(*) FROM usr_nicknames"
" WHERE Nickname='%s'",
- NewNicknameWithoutArroba)) // A nickname of another user is the same that this nickname
+ NewNickWithoutArroba)) // A nickname of another user is the same that this nickname
return API_CHECK_NEW_ACCOUNT_NICKNAME_REGISTERED_BY_ANOTHER_USER;
}
else // New nickname is not valid
@@ -905,8 +900,7 @@ int swad__loginByUserPasswordKey (struct soap *soap,
return ReturnCode;
/***** Check if user's email, @nickname or ID are valid *****/
- Str_Copy (UsrIDNickOrEmail,userID,
- Cns_MAX_BYTES_EMAIL_ADDRESS);
+ Str_Copy (UsrIDNickOrEmail,userID,sizeof (UsrIDNickOrEmail) - 1);
if (Nck_CheckIfNickWithArrobaIsValid (UsrIDNickOrEmail)) // 1: It's a nickname
{
Str_RemoveLeadingArrobas (UsrIDNickOrEmail);
@@ -998,7 +992,7 @@ int swad__loginByUserPasswordKey (struct soap *soap,
Gbl.Usrs.Me.UsrDat.Surname2,
Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
Str_Copy (loginByUserPasswordKeyOut->userFirstname,
- Gbl.Usrs.Me.UsrDat.FirstName,
+ Gbl.Usrs.Me.UsrDat.FrstName,
Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
Pho_BuildLinkToPhoto (&Gbl.Usrs.Me.UsrDat,PhotoURL);
@@ -1155,12 +1149,11 @@ int swad__loginBySessionKey (struct soap *soap,
Gbl.Usrs.Me.UsrDat.Surname2,
Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
Str_Copy (loginBySessionKeyOut->userFirstname,
- Gbl.Usrs.Me.UsrDat.FirstName,
+ Gbl.Usrs.Me.UsrDat.FrstName,
Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
Pho_BuildLinkToPhoto (&Gbl.Usrs.Me.UsrDat,PhotoURL);
- Str_Copy (loginBySessionKeyOut->userPhoto,PhotoURL,
- Cns_MAX_BYTES_WWW);
+ Str_Copy (loginBySessionKeyOut->userPhoto,PhotoURL,Cns_MAX_BYTES_WWW);
Str_Copy (loginBySessionKeyOut->userBirthday,
Gbl.Usrs.Me.UsrDat.Birthday.YYYYMMDD,
@@ -1274,8 +1267,7 @@ int swad__getNewPassword (struct soap *soap,
return ReturnCode;
/***** Check if user's email, @nickname or ID are valid *****/
- Str_Copy (UsrIDNickOrEmail,userID,
- Cns_MAX_BYTES_EMAIL_ADDRESS);
+ Str_Copy (UsrIDNickOrEmail,userID,sizeof (UsrIDNickOrEmail) - 1);
if (Nck_CheckIfNickWithArrobaIsValid (UsrIDNickOrEmail)) // 1: It's a nickname
{
Str_RemoveLeadingArrobas (UsrIDNickOrEmail);
@@ -1414,14 +1406,14 @@ int swad__getCourses (struct soap *soap,
/* Get course short name (row[1]) */
getCoursesOut->coursesArray.__ptr[NumRow].courseShortName =
(char *) soap_malloc (soap,Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1);
- Str_Copy (getCoursesOut->coursesArray.__ptr[NumRow].courseShortName,row[1],
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ Str_Copy (getCoursesOut->coursesArray.__ptr[NumRow].courseShortName,
+ row[1],Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
/* Get course full name (row[2]) */
getCoursesOut->coursesArray.__ptr[NumRow].courseFullName =
(char *) soap_malloc (soap,Cns_HIERARCHY_MAX_BYTES_FULL_NAME + 1);
- Str_Copy (getCoursesOut->coursesArray.__ptr[NumRow].courseFullName,row[2],
- Cns_HIERARCHY_MAX_BYTES_FULL_NAME);
+ Str_Copy (getCoursesOut->coursesArray.__ptr[NumRow].courseFullName,
+ row[2],Cns_HIERARCHY_MAX_BYTES_FULL_NAME);
/* Get role (row[3]) */
if (sscanf (row[3],"%u",&Role) != 1) // Role in this course
@@ -1531,8 +1523,7 @@ int swad__getCourseInfo (struct soap *soap,
&InfoSrc,&MustBeRead);
Length = strlen (NamesInWSForInfoSrc[InfoSrc]);
getCourseInfo->infoSrc = (char *) soap_malloc (soap,Length + 1);
- Str_Copy (getCourseInfo->infoSrc,NamesInWSForInfoSrc[InfoSrc],
- Length);
+ Str_Copy (getCourseInfo->infoSrc,NamesInWSForInfoSrc[InfoSrc],Length);
/***** Get info text *****/
getCourseInfo->infoTxt = NULL;
@@ -1596,8 +1587,7 @@ static int API_WriteSyllabusIntoHTMLBuffer (struct soap *soap,
if (Syl_LstItemsSyllabus.NumItems)
{
/***** Create a unique name for the file *****/
- snprintf (FileNameHTMLTmp,sizeof (FileNameHTMLTmp),
- "%s/%s_syllabus.html",
+ snprintf (FileNameHTMLTmp,sizeof (FileNameHTMLTmp),"%s/%s_syllabus.html",
Cfg_PATH_OUT_PRIVATE,Gbl.UniqueNameEncrypted);
/***** Create a new temporary file for writing and reading *****/
@@ -1617,7 +1607,7 @@ static int API_WriteSyllabusIntoHTMLBuffer (struct soap *soap,
Length = (size_t) ftell (FileHTMLTmp);
/* Allocate memory for buffer */
- if ((*HTMLBuffer = (char *) malloc (Length + 1)) == NULL)
+ if ((*HTMLBuffer = malloc (Length + 1)) == NULL)
{
fclose (FileHTMLTmp);
unlink (FileNameHTMLTmp);
@@ -1674,8 +1664,7 @@ static int API_WritePlainTextIntoHTMLBuffer (struct soap *soap,
if (TxtHTML[0])
{
/***** Create a unique name for the file *****/
- snprintf (FileNameHTMLTmp,sizeof (FileNameHTMLTmp),
- "%s/%s_info.html",
+ snprintf (FileNameHTMLTmp,sizeof (FileNameHTMLTmp),"%s/%s_info.html",
Cfg_PATH_OUT_PRIVATE,Gbl.UniqueNameEncrypted);
/***** Create a new temporary file for writing and reading *****/
@@ -1707,7 +1696,7 @@ static int API_WritePlainTextIntoHTMLBuffer (struct soap *soap,
Length = (size_t) ftell (FileHTMLTmp);
/***** Allocate memory for buffer *****/
- if ((*HTMLBuffer = (char *) malloc (Length + 1)) == NULL)
+ if ((*HTMLBuffer = malloc (Length + 1)) == NULL)
{
fclose (FileHTMLTmp);
unlink (FileNameHTMLTmp);
@@ -1757,16 +1746,14 @@ static int API_WritePageIntoHTMLBuffer (struct soap *soap,
/***** Open file with web page *****/
/* 1. Check if index.html exists */
- snprintf (PathRelFileHTML,sizeof (PathRelFileHTML),
- "%s/index.html",
+ snprintf (PathRelFileHTML,sizeof (PathRelFileHTML),"%s/index.html",
PathRelDirHTML);
if (Fil_CheckIfPathExists (PathRelFileHTML)) // TODO: Check if not empty?
FileExists = true;
else
{
/* 2. If index.html not exists, try index.htm */
- snprintf (PathRelFileHTML,sizeof (PathRelFileHTML),
- "%s/index.htm",
+ snprintf (PathRelFileHTML,sizeof (PathRelFileHTML),"%s/index.htm",
PathRelDirHTML);
if (Fil_CheckIfPathExists (PathRelFileHTML)) // TODO: Check if not empty?
FileExists = true;
@@ -1785,7 +1772,7 @@ static int API_WritePageIntoHTMLBuffer (struct soap *soap,
fseek (FileHTML,0L,SEEK_SET);
/* Allocate memory for buffer */
- if ((*HTMLBuffer = (char *) malloc (Length + 1)) == NULL)
+ if ((*HTMLBuffer = malloc (Length + 1)) == NULL)
{
fclose (FileHTML);
Lay_NotEnoughMemoryExit ();
@@ -1957,8 +1944,7 @@ int swad__findUsers (struct soap *soap,
Role = API_SvcRole_to_RolRole[userRole];
/***** Query users beloging to course or group from database *****/
- Str_Copy (Gbl.Search.Str,filter,
- Sch_MAX_BYTES_STRING_TO_FIND);
+ Str_Copy (Gbl.Search.Str,filter,sizeof (Gbl.Search.Str) - 1);
if (Gbl.Search.Str[0]) // Search some users
{
@@ -2149,8 +2135,8 @@ int swad__getGroupTypes (struct soap *soap,
/* Get group type name (row[1]) */
getGroupTypesOut->groupTypesArray.__ptr[NumRow].groupTypeName =
(char *) soap_malloc (soap,Grp_MAX_BYTES_GROUP_TYPE_NAME + 1);
- Str_Copy (getGroupTypesOut->groupTypesArray.__ptr[NumRow].groupTypeName,row[1],
- Grp_MAX_BYTES_GROUP_TYPE_NAME);
+ Str_Copy (getGroupTypesOut->groupTypesArray.__ptr[NumRow].groupTypeName,
+ row[1],Grp_MAX_BYTES_GROUP_TYPE_NAME);
/* Get whether enrolment is mandatory ('Y') or voluntary ('N') (row[2]) */
getGroupTypesOut->groupTypesArray.__ptr[NumRow].mandatory = (row[2][0] == 'Y') ? 1 :
@@ -2384,7 +2370,8 @@ int swad__sendMyGroups (struct soap *soap,
if (LstGrpsIWant.NumGrps) // If I have selected groups...
{
/***** Create a list of groups selected from myGroups *****/
- if ((LstGrpsIWant.GrpCods = (long *) calloc (LstGrpsIWant.NumGrps,sizeof (long))) == NULL)
+ if ((LstGrpsIWant.GrpCods = calloc (LstGrpsIWant.NumGrps,
+ sizeof (*LstGrpsIWant.GrpCods))) == NULL)
Lay_NotEnoughMemoryExit ();
for (NumGrp = 0, Ptr = myGroups;
*Ptr;
@@ -2502,8 +2489,7 @@ static void API_CopyUsrData (struct soap *soap,
/* Copy user's nickname */
Length = strlen (UsrDat->Nickname);
Usr->userNickname = (char *) soap_malloc (soap,Length + 1);
- Str_Copy (Usr->userNickname,UsrDat->Nickname,
- Length);
+ Str_Copy (Usr->userNickname,UsrDat->Nickname,Length);
/* Copy user's first ID */
if (UsrIDIsVisible && UsrDat->IDs.List)
@@ -2512,33 +2498,28 @@ static void API_CopyUsrData (struct soap *soap,
FirstID = "********";
Length = strlen (FirstID);
Usr->userID = (char *) soap_malloc (soap,Length + 1);
- Str_Copy (Usr->userID,FirstID,
- Length);
+ Str_Copy (Usr->userID,FirstID,Length);
/* Copy user's surname1 */
Length = strlen (UsrDat->Surname1);
Usr->userSurname1 = (char *) soap_malloc (soap,Length + 1);
- Str_Copy (Usr->userSurname1,UsrDat->Surname1,
- Length);
+ Str_Copy (Usr->userSurname1,UsrDat->Surname1,Length);
/* Copy user's surname2 */
Length = strlen (UsrDat->Surname2);
Usr->userSurname2 = (char *) soap_malloc (soap,Length + 1);
- Str_Copy (Usr->userSurname2,UsrDat->Surname2,
- Length);
+ Str_Copy (Usr->userSurname2,UsrDat->Surname2,Length);
/* Copy user's first name */
- Length = strlen (UsrDat->FirstName);
+ Length = strlen (UsrDat->FrstName);
Usr->userFirstname = (char *) soap_malloc (soap,Length + 1);
- Str_Copy (Usr->userFirstname,UsrDat->FirstName,
- Length);
+ Str_Copy (Usr->userFirstname,UsrDat->FrstName,Length);
/* User's photo URL */
Pho_BuildLinkToPhoto (UsrDat,PhotoURL);
Length = strlen (PhotoURL);
Usr->userPhoto = (char *) soap_malloc (soap,Length + 1);
- Str_Copy (Usr->userPhoto,PhotoURL,
- Length);
+ Str_Copy (Usr->userPhoto,PhotoURL,Length);
}
/*****************************************************************************/
@@ -2639,30 +2620,26 @@ int swad__getAttendanceEvents (struct soap *soap,
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].userSurname1 =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].userSurname1,
- Gbl.Usrs.Other.UsrDat.Surname1,
- Length);
+ Gbl.Usrs.Other.UsrDat.Surname1,Length);
Length = strlen (Gbl.Usrs.Other.UsrDat.Surname2);
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].userSurname2 =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].userSurname2,
- Gbl.Usrs.Other.UsrDat.Surname2,
- Length);
+ Gbl.Usrs.Other.UsrDat.Surname2,Length);
- Length = strlen (Gbl.Usrs.Other.UsrDat.FirstName);
+ Length = strlen (Gbl.Usrs.Other.UsrDat.FrstName);
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].userFirstname =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].userFirstname,
- Gbl.Usrs.Other.UsrDat.FirstName,
- Length);
+ Gbl.Usrs.Other.UsrDat.FrstName,Length);
Pho_BuildLinkToPhoto (&Gbl.Usrs.Other.UsrDat,PhotoURL);
Length = strlen (PhotoURL);
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].userPhoto =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].userPhoto,
- PhotoURL,
- Length);
+ PhotoURL,Length);
}
else
{
@@ -2692,15 +2669,15 @@ int swad__getAttendanceEvents (struct soap *soap,
Length = strlen (row[6]);
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].title =
(char *) soap_malloc (soap,Length + 1);
- Str_Copy (getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].title,row[6],
- Length);
+ Str_Copy (getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].title,
+ row[6],Length);
/* Get Txt (row[7]) */
Length = strlen (row[7]);
getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].text =
(char *) soap_malloc (soap,Length + 1);
- Str_Copy (getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].text,row[7],
- Length);
+ Str_Copy (getAttendanceEventsOut->eventsArray.__ptr[NumAttEvent].text,
+ row[7],Length);
/* Get list of groups for this attendance event */
API_GetListGrpsInAttendanceEventFromDB (soap,
@@ -2753,12 +2730,10 @@ static void API_GetListGrpsInAttendanceEventFromDB (struct soap *soap,
/* Get group code (row[0]) */
GrpCod = Str_ConvertStrCodToLongCod (row[0]);
- snprintf (GrpCodStr,sizeof (GrpCodStr),
- NumGrp ? ",%ld" :
- "%ld",
+ snprintf (GrpCodStr,sizeof (GrpCodStr),NumGrp ? ",%ld" :
+ "%ld",
GrpCod);
- Str_Concat (*ListGroups,GrpCodStr,
- Length);
+ Str_Concat (*ListGroups,GrpCodStr,Length);
}
}
@@ -2855,8 +2830,7 @@ int swad__sendAttendanceEvent (struct soap *soap,
return soap_receiver_fault (soap,
"Request forbidden",
"Title of attendance event is empty");
- Str_Copy (Event.Title,title,
- Att_MAX_BYTES_ATTENDANCE_EVENT_TITLE);
+ Str_Copy (Event.Title,title,sizeof (Event.Title) - 1);
/* Create a list of groups selected */
API_GetLstGrpsSel (groups);
@@ -2965,7 +2939,8 @@ static void API_GetLstGrpsSel (const char *Groups)
// Here NestedCalls is always 0
Gbl.Crs.Grps.LstGrpsSel.NestedCalls++;
// Here NestedCalls is always 1
- if ((Gbl.Crs.Grps.LstGrpsSel.GrpCods = (long *) calloc (Gbl.Crs.Grps.LstGrpsSel.NumGrps,sizeof (long))) == NULL)
+ if ((Gbl.Crs.Grps.LstGrpsSel.GrpCods = calloc (Gbl.Crs.Grps.LstGrpsSel.NumGrps,
+ sizeof (*Gbl.Crs.Grps.LstGrpsSel.GrpCods))) == NULL)
Lay_NotEnoughMemoryExit ();
for (Ptr = Groups, NumGrp = 0;
@@ -3105,8 +3080,7 @@ int swad__getAttendanceUsers (struct soap *soap,
getAttendanceUsersOut->usersArray.__ptr[NumRow].userNickname =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getAttendanceUsersOut->usersArray.__ptr[NumRow].userNickname,
- Gbl.Usrs.Other.UsrDat.Nickname,
- Length);
+ Gbl.Usrs.Other.UsrDat.Nickname,Length);
if (Gbl.Usrs.Other.UsrDat.IDs.Num)
{
@@ -3114,8 +3088,7 @@ int swad__getAttendanceUsers (struct soap *soap,
getAttendanceUsersOut->usersArray.__ptr[NumRow].userID =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getAttendanceUsersOut->usersArray.__ptr[NumRow].userID,
- Gbl.Usrs.Other.UsrDat.IDs.List[0].ID,
- Length);
+ Gbl.Usrs.Other.UsrDat.IDs.List[0].ID,Length);
}
else
{
@@ -3128,30 +3101,26 @@ int swad__getAttendanceUsers (struct soap *soap,
getAttendanceUsersOut->usersArray.__ptr[NumRow].userSurname1 =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getAttendanceUsersOut->usersArray.__ptr[NumRow].userSurname1,
- Gbl.Usrs.Other.UsrDat.Surname1,
- Length);
+ Gbl.Usrs.Other.UsrDat.Surname1,Length);
Length = strlen (Gbl.Usrs.Other.UsrDat.Surname2);
getAttendanceUsersOut->usersArray.__ptr[NumRow].userSurname2 =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getAttendanceUsersOut->usersArray.__ptr[NumRow].userSurname2,
- Gbl.Usrs.Other.UsrDat.Surname2,
- Length);
+ Gbl.Usrs.Other.UsrDat.Surname2,Length);
- Length = strlen (Gbl.Usrs.Other.UsrDat.FirstName);
+ Length = strlen (Gbl.Usrs.Other.UsrDat.FrstName);
getAttendanceUsersOut->usersArray.__ptr[NumRow].userFirstname =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getAttendanceUsersOut->usersArray.__ptr[NumRow].userFirstname,
- Gbl.Usrs.Other.UsrDat.FirstName,
- Length);
+ Gbl.Usrs.Other.UsrDat.FrstName,Length);
Pho_BuildLinkToPhoto (&Gbl.Usrs.Other.UsrDat,PhotoURL);
Length = strlen (PhotoURL);
getAttendanceUsersOut->usersArray.__ptr[NumRow].userPhoto =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getAttendanceUsersOut->usersArray.__ptr[NumRow].userPhoto,
- PhotoURL,
- Length);
+ PhotoURL,Length);
}
else
{
@@ -3244,7 +3213,7 @@ int swad__sendAttendanceUsers (struct soap *soap,
/* Allocate subquery used to mark not present users as absent */
Length = 256 + NumCodsInList * (1 + Cns_MAX_DECIMAL_DIGITS_LONG + 1) - 1;
- if ((SubQueryAllUsrs = (char *) malloc (Length + 1)) == NULL)
+ if ((SubQueryAllUsrs = malloc (Length + 1)) == NULL)
return soap_receiver_fault (soap,
"Not enough memory",
"Not enough memory to store list of users");
@@ -3271,14 +3240,12 @@ int swad__sendAttendanceUsers (struct soap *soap,
{
if (sendAttendanceUsersOut->numUsers)
{
- snprintf (SubQueryOneUsr,sizeof (SubQueryOneUsr),
- ",%ld",UsrDat.UsrCod);
- Str_Concat (SubQueryAllUsrs,SubQueryOneUsr,
- Length);
+ snprintf (SubQueryOneUsr,sizeof (SubQueryOneUsr),",%ld",
+ UsrDat.UsrCod);
+ Str_Concat (SubQueryAllUsrs,SubQueryOneUsr,Length);
}
else
- snprintf (SubQueryAllUsrs,Length,
- " AND UsrCod NOT IN (%ld",
+ snprintf (SubQueryAllUsrs,Length," AND UsrCod NOT IN (%ld",
UsrDat.UsrCod);
}
@@ -3290,8 +3257,7 @@ int swad__sendAttendanceUsers (struct soap *soap,
{
/* Mark not present users as absent in table of users */
if (sendAttendanceUsersOut->numUsers)
- Str_Concat (SubQueryAllUsrs,")",
- Length);
+ Str_Concat (SubQueryAllUsrs,")",Length);
DB_QueryUPDATE ("can not set other users as absent",
"UPDATE att_usr SET Present='N'"
@@ -3411,8 +3377,7 @@ int swad__getNotifications (struct soap *soap,
getNotificationsOut->notificationsArray.__ptr[NumNotif].eventType =
(char *) soap_malloc (soap,Ntf_MAX_BYTES_NOTIFY_EVENT + 1);
Str_Copy (getNotificationsOut->notificationsArray.__ptr[NumNotif].eventType,
- Ntf_WSNotifyEvents[NotifyEvent],
- Ntf_MAX_BYTES_NOTIFY_EVENT);
+ Ntf_WSNotifyEvents[NotifyEvent],Ntf_MAX_BYTES_NOTIFY_EVENT);
/* Get time of the event (row[2]) */
EventTime = 0L;
@@ -3450,15 +3415,14 @@ int swad__getNotifications (struct soap *soap,
getNotificationsOut->notificationsArray.__ptr[NumNotif].userFirstname =
(char *) soap_malloc (soap,Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1);
Str_Copy (getNotificationsOut->notificationsArray.__ptr[NumNotif].userFirstname,
- Gbl.Usrs.Other.UsrDat.FirstName,
+ Gbl.Usrs.Other.UsrDat.FrstName,
Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
Pho_BuildLinkToPhoto (&Gbl.Usrs.Other.UsrDat,PhotoURL);
getNotificationsOut->notificationsArray.__ptr[NumNotif].userPhoto =
(char *) soap_malloc (soap,Cns_MAX_BYTES_WWW + 1);
Str_Copy (getNotificationsOut->notificationsArray.__ptr[NumNotif].userPhoto,
- PhotoURL,
- Cns_MAX_BYTES_WWW);
+ PhotoURL,Cns_MAX_BYTES_WWW);
}
else
{
@@ -3529,8 +3493,7 @@ int swad__getNotifications (struct soap *soap,
getNotificationsOut->notificationsArray.__ptr[NumNotif].summary =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getNotificationsOut->notificationsArray.__ptr[NumNotif].summary,
- SummaryStr,
- Length);
+ SummaryStr,Length);
if (ContentStr == NULL)
{
@@ -3544,8 +3507,7 @@ int swad__getNotifications (struct soap *soap,
getNotificationsOut->notificationsArray.__ptr[NumNotif].content =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getNotificationsOut->notificationsArray.__ptr[NumNotif].content,
- ContentStr,
- Length);
+ ContentStr,Length);
/* Free memory used by content string */
free (ContentStr);
@@ -3773,15 +3735,13 @@ int swad__sendMessage (struct soap *soap,
}
/***** Allocate space for query *****/
- if ((Query = (char *) malloc (API_MAX_BYTES_QUERY_RECIPIENTS + 1)) == NULL)
+ if ((Query = malloc (API_MAX_BYTES_QUERY_RECIPIENTS + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Build query for recipients from database *****/
if (ReplyUsrCod > 0)
snprintf (Query,API_MAX_BYTES_QUERY_RECIPIENTS + 1,
- "SELECT UsrCod FROM usr_data"
- " WHERE UsrCod=%ld",
- ReplyUsrCod);
+ "SELECT UsrCod FROM usr_data WHERE UsrCod=%ld",ReplyUsrCod);
else
Query[0] = '\0';
@@ -3808,8 +3768,7 @@ int swad__sendMessage (struct soap *soap,
if (FirstNickname)
{
if (ReplyUsrCod > 0)
- Str_Concat (Query," UNION ",
- API_MAX_BYTES_QUERY_RECIPIENTS);
+ Str_Concat (Query," UNION ",API_MAX_BYTES_QUERY_RECIPIENTS);
Str_Concat (Query,"SELECT UsrCod FROM usr_nicknames"
" WHERE Nickname IN ('",
API_MAX_BYTES_QUERY_RECIPIENTS);
@@ -3817,17 +3776,13 @@ int swad__sendMessage (struct soap *soap,
ThereAreNicknames = true;
}
else
- Str_Concat (Query,",'",
- API_MAX_BYTES_QUERY_RECIPIENTS);
- Str_Concat (Query,Nickname,
- API_MAX_BYTES_QUERY_RECIPIENTS);
- Str_Concat (Query,"'",
- API_MAX_BYTES_QUERY_RECIPIENTS);
+ Str_Concat (Query,",'",API_MAX_BYTES_QUERY_RECIPIENTS);
+ Str_Concat (Query,Nickname,API_MAX_BYTES_QUERY_RECIPIENTS);
+ Str_Concat (Query,"'",API_MAX_BYTES_QUERY_RECIPIENTS);
}
}
if (ThereAreNicknames)
- Str_Concat (Query,")",
- API_MAX_BYTES_QUERY_RECIPIENTS);
+ Str_Concat (Query,")",API_MAX_BYTES_QUERY_RECIPIENTS);
/***** Initialize output structure *****/
sendMessageOut->numUsers = 0;
@@ -4108,24 +4063,19 @@ int swad__getTestConfig (struct soap *soap,
/* Convert from visibility to old feedback */
/* TODO: Remove these lines in 2021 */
if (!TstVis_IsVisibleTotalScore (TstCfg_GetConfigVisibility ()))
- Str_Copy (getTestConfigOut->feedback,
- "nothing",
+ Str_Copy (getTestConfigOut->feedback,"nothing",
TstPrn_MAX_BYTES_FEEDBACK_TYPE);
else if (!TstVis_IsVisibleEachQstScore (TstCfg_GetConfigVisibility ()))
- Str_Copy (getTestConfigOut->feedback,
- "totalResult",
+ Str_Copy (getTestConfigOut->feedback,"totalResult",
TstPrn_MAX_BYTES_FEEDBACK_TYPE);
else if (!TstVis_IsVisibleCorrectAns (TstCfg_GetConfigVisibility ()))
- Str_Copy (getTestConfigOut->feedback,
- "eachResult",
+ Str_Copy (getTestConfigOut->feedback,"eachResult",
TstPrn_MAX_BYTES_FEEDBACK_TYPE);
else if (!TstVis_IsVisibleFeedbackTxt (TstCfg_GetConfigVisibility ()))
- Str_Copy (getTestConfigOut->feedback,
- "eachGoodBad",
+ Str_Copy (getTestConfigOut->feedback,"eachGoodBad",
TstPrn_MAX_BYTES_FEEDBACK_TYPE);
else
- Str_Copy (getTestConfigOut->feedback,
- "fullFeedback",
+ Str_Copy (getTestConfigOut->feedback,"fullFeedback",
TstPrn_MAX_BYTES_FEEDBACK_TYPE);
/***** Get number of tests *****/
@@ -4510,14 +4460,14 @@ static int API_GetTstAnswers (struct soap *soap,
/* Get answer (row[3]) */
getTestsOut->answersArray.__ptr[NumRow].answerText =
(char *) soap_malloc (soap,Cns_MAX_BYTES_TEXT + 1);
- Str_Copy (getTestsOut->answersArray.__ptr[NumRow].answerText,row[3],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (getTestsOut->answersArray.__ptr[NumRow].answerText,
+ row[3],Cns_MAX_BYTES_TEXT);
/* Get feedback (row[4]) */
getTestsOut->answersArray.__ptr[NumRow].answerFeedback =
(char *) soap_malloc (soap,Cns_MAX_BYTES_TEXT + 1);
- Str_Copy (getTestsOut->answersArray.__ptr[NumRow].answerFeedback,row[4],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (getTestsOut->answersArray.__ptr[NumRow].answerFeedback,
+ row[4],Cns_MAX_BYTES_TEXT);
}
}
@@ -4667,18 +4617,13 @@ int swad__getTrivialQuestion (struct soap *soap,
/* Add this degree to query */
if (FirstDegree)
{
- snprintf (DegreesStr,sizeof (DegreesStr),
- "%ld",
- DegCod);
+ snprintf (DegreesStr,sizeof (DegreesStr),"%ld",DegCod);
FirstDegree = false;
}
else
{
- snprintf (DegStr,sizeof (DegStr),
- ",%ld",
- DegCod);
- Str_Concat (DegreesStr,DegStr,
- API_MAX_BYTES_DEGREES_STR);
+ snprintf (DegStr,sizeof (DegStr),",%ld",DegCod);
+ Str_Concat (DegreesStr,DegStr,sizeof (DegreesStr) - 1);
}
}
}
@@ -4823,14 +4768,14 @@ int swad__getTrivialQuestion (struct soap *soap,
/* Get answer (row[3]) */
getTrivialQuestionOut->answersArray.__ptr[NumRow].answerText =
(char *) soap_malloc (soap,Cns_MAX_BYTES_TEXT + 1);
- Str_Copy (getTrivialQuestionOut->answersArray.__ptr[NumRow].answerText,row[3],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (getTrivialQuestionOut->answersArray.__ptr[NumRow].answerText,
+ row[3],Cns_MAX_BYTES_TEXT);
/* Get feedback (row[4]) */
getTrivialQuestionOut->answersArray.__ptr[NumRow].answerFeedback =
(char *) soap_malloc (soap,Cns_MAX_BYTES_TEXT + 1);
- Str_Copy (getTrivialQuestionOut->answersArray.__ptr[NumRow].answerFeedback,row[4],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (getTrivialQuestionOut->answersArray.__ptr[NumRow].answerFeedback,
+ row[4],Cns_MAX_BYTES_TEXT);
}
}
@@ -4943,30 +4888,26 @@ int swad__getGames (struct soap *soap,
getGamesOut->gamesArray.__ptr[NumGame].userSurname1 =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getGamesOut->gamesArray.__ptr[NumGame].userSurname1,
- Gbl.Usrs.Other.UsrDat.Surname1,
- Length);
+ Gbl.Usrs.Other.UsrDat.Surname1,Length);
Length = strlen (Gbl.Usrs.Other.UsrDat.Surname2);
getGamesOut->gamesArray.__ptr[NumGame].userSurname2 =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getGamesOut->gamesArray.__ptr[NumGame].userSurname2,
- Gbl.Usrs.Other.UsrDat.Surname2,
- Length);
+ Gbl.Usrs.Other.UsrDat.Surname2,Length);
- Length = strlen (Gbl.Usrs.Other.UsrDat.FirstName);
+ Length = strlen (Gbl.Usrs.Other.UsrDat.FrstName);
getGamesOut->gamesArray.__ptr[NumGame].userFirstname =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getGamesOut->gamesArray.__ptr[NumGame].userFirstname,
- Gbl.Usrs.Other.UsrDat.FirstName,
- Length);
+ Gbl.Usrs.Other.UsrDat.FrstName,Length);
Pho_BuildLinkToPhoto (&Gbl.Usrs.Other.UsrDat,PhotoURL);
Length = strlen (PhotoURL);
getGamesOut->gamesArray.__ptr[NumGame].userPhoto =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getGamesOut->gamesArray.__ptr[NumGame].userPhoto,
- PhotoURL,
- Length);
+ PhotoURL,Length);
}
else
{
@@ -5000,15 +4941,13 @@ int swad__getGames (struct soap *soap,
Length = strlen (row[6]);
getGamesOut->gamesArray.__ptr[NumGame].title =
(char *) soap_malloc (soap,Length + 1);
- Str_Copy (getGamesOut->gamesArray.__ptr[NumGame].title,row[6],
- Length);
+ Str_Copy (getGamesOut->gamesArray.__ptr[NumGame].title,row[6],Length);
/* Get Txt (row[7]) */
Length = strlen (row[7]);
getGamesOut->gamesArray.__ptr[NumGame].text =
(char *) soap_malloc (soap,Length + 1);
- Str_Copy (getGamesOut->gamesArray.__ptr[NumGame].text,row[7],
- Length);
+ Str_Copy (getGamesOut->gamesArray.__ptr[NumGame].text,row[7],Length);
}
}
@@ -5134,30 +5073,26 @@ int swad__getMatches (struct soap *soap,
getMatchesOut->matchesArray.__ptr[NumMatch].userSurname1 =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getMatchesOut->matchesArray.__ptr[NumMatch].userSurname1,
- Gbl.Usrs.Other.UsrDat.Surname1,
- Length);
+ Gbl.Usrs.Other.UsrDat.Surname1,Length);
Length = strlen (Gbl.Usrs.Other.UsrDat.Surname2);
getMatchesOut->matchesArray.__ptr[NumMatch].userSurname2 =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getMatchesOut->matchesArray.__ptr[NumMatch].userSurname2,
- Gbl.Usrs.Other.UsrDat.Surname2,
- Length);
+ Gbl.Usrs.Other.UsrDat.Surname2,Length);
- Length = strlen (Gbl.Usrs.Other.UsrDat.FirstName);
+ Length = strlen (Gbl.Usrs.Other.UsrDat.FrstName);
getMatchesOut->matchesArray.__ptr[NumMatch].userFirstname =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getMatchesOut->matchesArray.__ptr[NumMatch].userFirstname,
- Gbl.Usrs.Other.UsrDat.FirstName,
- Length);
+ Gbl.Usrs.Other.UsrDat.FrstName,Length);
Pho_BuildLinkToPhoto (&Gbl.Usrs.Other.UsrDat,PhotoURL);
Length = strlen (PhotoURL);
getMatchesOut->matchesArray.__ptr[NumMatch].userPhoto =
(char *) soap_malloc (soap,Length + 1);
Str_Copy (getMatchesOut->matchesArray.__ptr[NumMatch].userPhoto,
- PhotoURL,
- Length);
+ PhotoURL,Length);
}
else
{
@@ -5450,12 +5385,10 @@ static void API_GetListGrpsInGameFromDB (struct soap *soap,
/* Get group code (row[0]) */
GrpCod = Str_ConvertStrCodToLongCod (row[0]);
- snprintf (GrpCodStr,sizeof (GrpCodStr),
- NumGrp ? ",%ld" :
- "%ld",
+ snprintf (GrpCodStr,sizeof (GrpCodStr),NumGrp ? ",%ld" :
+ "%ld",
GrpCod);
- Str_Concat (*ListGroups,GrpCodStr,
- Length);
+ Str_Concat (*ListGroups,GrpCodStr,Length);
}
}
@@ -5571,22 +5504,20 @@ int swad__getDirectoryTree (struct soap *soap,
Gbl.Crs.Grps.GrpCod = (groupCode > 0) ? (long) groupCode :
-1L;
- snprintf (Gbl.Crs.PathPriv,sizeof (Gbl.Crs.PathPriv),
- "%s/%ld",
+ snprintf (Gbl.Crs.PathPriv,sizeof (Gbl.Crs.PathPriv),"%s/%ld",
Cfg_PATH_CRS_PRIVATE,Gbl.Hierarchy.Crs.CrsCod);
Brw_InitializeFileBrowser ();
Str_Copy (Gbl.FileBrowser.FilFolLnk.Path,Brw_RootFolderInternalNames[Gbl.FileBrowser.Type],
- PATH_MAX);
+ sizeof (Gbl.FileBrowser.FilFolLnk.Path) - 1);
Str_Copy (Gbl.FileBrowser.FilFolLnk.Name,".",
- NAME_MAX);
+ sizeof (Gbl.FileBrowser.FilFolLnk.Name) - 1);
Brw_SetFullPathInTree ();
/* Check if exists the directory for HTML output. If not exists, create it */
Fil_CreateDirIfNotExists (Cfg_PATH_OUT_PRIVATE);
/* Create a unique name for the file */
- snprintf (XMLFileName,sizeof (XMLFileName),
- "%s/%s.xml",
+ snprintf (XMLFileName,sizeof (XMLFileName),"%s/%s.xml",
Cfg_PATH_OUT_PRIVATE,Gbl.UniqueNameEncrypted);
/* Open file for writing and reading */
@@ -5644,17 +5575,15 @@ static void API_ListDir (unsigned Level,const char *Path,const char *PathInTree)
if (strcmp (FileList[NumFile]->d_name,".") &&
strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".."
{
- snprintf (PathFileRel,sizeof (PathFileRel),
- "%s/%s",
+ snprintf (PathFileRel,sizeof (PathFileRel),"%s/%s",
Path,FileList[NumFile]->d_name);
- snprintf (PathFileInExplTree,sizeof (PathFileInExplTree),
- "%s/%s",
+ snprintf (PathFileInExplTree,sizeof (PathFileInExplTree),"%s/%s",
PathInTree,FileList[NumFile]->d_name);
Str_Copy (Gbl.FileBrowser.FilFolLnk.Path,PathInTree,
- PATH_MAX);
+ sizeof (Gbl.FileBrowser.FilFolLnk.Path) - 1);
Str_Copy (Gbl.FileBrowser.FilFolLnk.Name,FileList[NumFile]->d_name,
- NAME_MAX);
+ sizeof (Gbl.FileBrowser.FilFolLnk.Name) - 1);
if (!lstat (PathFileRel,&FileStatus)) // On success ==> 0 is returned
{
@@ -5884,9 +5813,9 @@ int swad__getFile (struct soap *soap,
/***** Set paths *****/
Brw_InitializeFileBrowser ();
Str_Copy (Gbl.FileBrowser.FilFolLnk.Path,FileMetadata.FilFolLnk.Path,
- PATH_MAX);
+ sizeof (Gbl.FileBrowser.FilFolLnk.Path) - 1);
Str_Copy (Gbl.FileBrowser.FilFolLnk.Name,FileMetadata.FilFolLnk.Name,
- NAME_MAX);
+ sizeof (Gbl.FileBrowser.FilFolLnk.Name) - 1);
Brw_SetFullPathInTree ();
/***** Get file size and date *****/
@@ -5901,11 +5830,9 @@ int swad__getFile (struct soap *soap,
URL);
/***** Copy data into output structure *****/
- Str_Copy (getFileOut->fileName,FileMetadata.FilFolLnk.Name,
- NAME_MAX);
+ Str_Copy (getFileOut->fileName,FileMetadata.FilFolLnk.Name,NAME_MAX);
- Str_Copy (getFileOut->URL,URL,
- Cns_MAX_BYTES_WWW);
+ Str_Copy (getFileOut->URL,URL,Cns_MAX_BYTES_WWW);
getFileOut->size = (int) FileMetadata.Size;
@@ -5923,8 +5850,7 @@ int swad__getFile (struct soap *soap,
Usr_MAX_BYTES_FULL_NAME);
Pho_BuildLinkToPhoto (&Gbl.Usrs.Other.UsrDat,PhotoURL);
- Str_Copy (getFileOut->publisherPhoto,PhotoURL,
- Cns_MAX_BYTES_WWW);
+ Str_Copy (getFileOut->publisherPhoto,PhotoURL,Cns_MAX_BYTES_WWW);
}
return SOAP_OK;
@@ -6015,8 +5941,7 @@ int swad__getMarks (struct soap *soap,
{
Length = strlen (ContentStr);
getMarksOut->content = (char *) soap_malloc (soap,Length + 1);
- Str_Copy (getMarksOut->content,ContentStr,
- Length);
+ Str_Copy (getMarksOut->content,ContentStr,Length);
free (ContentStr);
ContentStr = NULL;
}
diff --git a/swad_ID.c b/swad_ID.c
index 530de2ab..08272fc2 100644
--- a/swad_ID.c
+++ b/swad_ID.c
@@ -121,7 +121,7 @@ void ID_GetListIDsFromUsrCod (struct UsrData *UsrDat)
/* Get ID from row[0] */
Str_Copy (UsrDat->IDs.List[NumID].ID,row[0],
- ID_MAX_BYTES_USR_ID);
+ sizeof (UsrDat->IDs.List[NumID].ID) - 1);
/* Get if ID is confirmed from row[1] */
UsrDat->IDs.List[NumID].Confirmed = (row[1][0] == 'Y');
@@ -146,7 +146,7 @@ void ID_ReallocateListIDs (struct UsrData *UsrDat,unsigned NumIDs)
UsrDat->IDs.Num = NumIDs;
/***** Allocate space for the list *****/
- if ((UsrDat->IDs.List = (struct ListIDs *) malloc (NumIDs * sizeof (struct ListIDs))) == NULL)
+ if ((UsrDat->IDs.List = malloc (NumIDs * sizeof (*UsrDat->IDs.List))) == NULL)
Lay_NotEnoughMemoryExit ();
}
@@ -193,7 +193,7 @@ unsigned ID_GetListUsrCodsFromUsrID (struct UsrData *UsrDat,
/***** Allocate memory for subquery string *****/
MaxLength = 512 + UsrDat->IDs.Num * (1 + ID_MAX_BYTES_USR_ID + 1) - 1;
- if ((SubQueryAllUsrs = (char *) malloc (MaxLength + 1)) == NULL)
+ if ((SubQueryAllUsrs = malloc (MaxLength + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
SubQueryAllUsrs[0] = '\0';
@@ -203,12 +203,10 @@ unsigned ID_GetListUsrCodsFromUsrID (struct UsrData *UsrDat,
NumID++)
{
if (NumID)
- Str_Concat (SubQueryAllUsrs,",",
- MaxLength);
+ Str_Concat (SubQueryAllUsrs,",",MaxLength);
sprintf (SubQueryOneUsr,"'%s'",UsrDat->IDs.List[NumID].ID);
- Str_Concat (SubQueryAllUsrs,SubQueryOneUsr,
- MaxLength);
+ Str_Concat (SubQueryAllUsrs,SubQueryOneUsr,MaxLength);
}
if (CheckPassword)
@@ -435,7 +433,7 @@ bool ID_ICanSeeOtherUsrIDs (const struct UsrData *UsrDat)
if (!UsrDat->Password[0] && // User has no password (never logged)
!UsrDat->Surname1[0] && // and who has no surname 1 (nobody filled user's surname 1)
!UsrDat->Surname2[0] && // and who has no surname 2 (nobody filled user's surname 2)
- !UsrDat->FirstName[0] && // and who has no first name (nobody filled user's first name)
+ !UsrDat->FrstName[0] && // and who has no first name (nobody filled user's first name)
!UsrDat->Email[0]) // and who has no email (nobody filled user's email)
return true;
@@ -491,7 +489,7 @@ static void ID_PutLinkToConfirmID (struct UsrData *UsrDat,unsigned NumID,
break;
}
}
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
Par_PutHiddenParamString (NULL,"UsrID",UsrDat->IDs.List[NumID].ID);
/***** Put link *****/
@@ -517,9 +515,7 @@ void ID_ShowFormChangeMyID (bool IShouldFillInID)
HTM_SECTION_Begin (ID_ID_SECTION_ID);
/***** Begin box *****/
- snprintf (StrRecordWidth,sizeof (StrRecordWidth),
- "%upx",
- Rec_RECORD_WIDTH);
+ snprintf (StrRecordWidth,sizeof (StrRecordWidth),"%upx",Rec_RECORD_WIDTH);
Box_BoxBegin (StrRecordWidth,Txt_ID,
Acc_PutLinkToRemoveMyAccount,NULL,
Hlp_PROFILE_Account,Box_NOT_CLOSABLE);
@@ -549,9 +545,7 @@ void ID_ShowFormChangeOtherUsrID (void)
HTM_SECTION_Begin (ID_ID_SECTION_ID);
/***** Begin box *****/
- snprintf (StrRecordWidth,sizeof (StrRecordWidth),
- "%upx",
- Rec_RECORD_WIDTH);
+ snprintf (StrRecordWidth,sizeof (StrRecordWidth),"%upx",Rec_RECORD_WIDTH);
Box_BoxBegin (StrRecordWidth,Txt_ID,
NULL,NULL,
Hlp_PROFILE_Account,Box_NOT_CLOSABLE);
@@ -704,7 +698,7 @@ static void ID_ShowFormChangeUsrID (bool ItsMe,bool IShouldFillInID)
break;
}
Frm_StartFormAnchor (NextAction,ID_ID_SECTION_ID);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
}
HTM_INPUT_TEXT ("NewID",ID_MAX_BYTES_USR_ID,
UsrDat->IDs.Num ? UsrDat->IDs.List[UsrDat->IDs.Num - 1].ID :
@@ -733,7 +727,7 @@ static void ID_PutParamsRemoveOtherID (void *ID)
{
if (ID)
{
- Usr_PutParamUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
Par_PutHiddenParamString (NULL,"UsrID",(char *) ID);
}
}
diff --git a/swad_MFU.c b/swad_MFU.c
index b0df7c94..34952419 100644
--- a/swad_MFU.c
+++ b/swad_MFU.c
@@ -78,7 +78,8 @@ extern struct Globals Gbl;
void MFU_AllocateMFUActions (struct MFU_ListMFUActions *ListMFUActions,unsigned MaxActionsShown)
{
- if ((ListMFUActions->Actions = (Act_Action_t *) malloc (sizeof (Act_Action_t) * MaxActionsShown)) == NULL)
+ if ((ListMFUActions->Actions = malloc (MaxActionsShown *
+ sizeof (*ListMFUActions->Actions))) == NULL)
Lay_ShowErrorAndExit ("Can not allocate memory for list of most frequently used actions.");
}
@@ -236,12 +237,9 @@ void MFU_WriteBigMFUActions (struct MFU_ListMFUActions *ListMFUActions)
{
/* Action string */
Str_Copy (TabStr,Txt_TABS_TXT[Act_GetTab (Act_GetSuperAction (Action))],
- MFU_MAX_BYTES_TAB);
- Str_Copy (MenuStr,Title,
- MFU_MAX_BYTES_MENU);
- snprintf (TabMenuStr,sizeof (TabMenuStr),
- "%s > %s",
- TabStr,MenuStr);
+ sizeof (TabStr) - 1);
+ Str_Copy (MenuStr,Title,sizeof (MenuStr) - 1);
+ snprintf (TabMenuStr,sizeof (TabMenuStr),"%s > %s",TabStr,MenuStr);
/* Icon and text */
HTM_LI_Begin ("class=\"ICO_HIGHLIGHT\"");
@@ -297,12 +295,9 @@ void MFU_WriteSmallMFUActions (struct MFU_ListMFUActions *ListMFUActions)
{
/* Action string */
Str_Copy (TabStr,Txt_TABS_TXT[Act_GetTab (Act_GetSuperAction (Action))],
- MFU_MAX_BYTES_TAB);
- Str_Copy (MenuStr,Title,
- MFU_MAX_BYTES_MENU);
- snprintf (TabMenuStr,sizeof (TabMenuStr),
- "%s > %s",
- TabStr,MenuStr);
+ sizeof (TabStr) - 1);
+ Str_Copy (MenuStr,Title,sizeof (MenuStr) - 1);
+ snprintf (TabMenuStr,sizeof (TabMenuStr),"%s > %s",TabStr,MenuStr);
/* Icon and text */
HTM_LI_Begin ("class=\"ICO_HIGHLIGHT\"");
diff --git a/swad_RSS.c b/swad_RSS.c
index b557737e..7ead6ced 100644
--- a/swad_RSS.c
+++ b/swad_RSS.c
@@ -66,14 +66,12 @@ void RSS_UpdateRSSFileForACrs (struct Crs_Course *Crs)
struct tm *tm;
/***** Create RSS directory if not exists *****/
- snprintf (PathRelPublRSSDir,sizeof (PathRelPublRSSDir),
- "%s/%ld/%s",
+ snprintf (PathRelPublRSSDir,sizeof (PathRelPublRSSDir),"%s/%ld/%s",
Cfg_PATH_CRS_PUBLIC,Crs->CrsCod,Cfg_RSS_FOLDER);
Fil_CreateDirIfNotExists (PathRelPublRSSDir);
/***** Create RSS file *****/
- snprintf (PathRelPublRSSFile,sizeof (PathRelPublRSSFile),
- "%s/%s",
+ snprintf (PathRelPublRSSFile,sizeof (PathRelPublRSSFile),"%s/%s",
PathRelPublRSSDir,Cfg_RSS_FILE);
if ((FileRSS = fopen (PathRelPublRSSFile,"wb")) == NULL)
Lay_ShowErrorAndExit ("Can not create RSS file.");
@@ -196,8 +194,7 @@ static void RSS_WriteNotices (FILE *FileRSS,struct Crs_Course *Crs)
fprintf (FileRSS,"- \n");
/* Write title (first characters) of the notice */
- Str_Copy (Content,row[3],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Content,row[3],sizeof (Content) - 1);
Str_LimitLengthHTMLStr (Content,40); // Remove when notice has a Subject
fprintf (FileRSS,"%s: ",Txt_Notice);
Str_FilePrintStrChangingBRToRetAndNBSPToSpace (FileRSS,Content);
@@ -208,16 +205,15 @@ static void RSS_WriteNotices (FILE *FileRSS,struct Crs_Course *Crs)
Cfg_URL_SWAD_CGI,Crs->CrsCod);
/* Write full content of the notice */
- Str_Copy (Content,row[3],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Content,row[3],sizeof (Content) - 1);
Str_InsertLinks (Content,Cns_MAX_BYTES_TEXT,40);
fprintf (FileRSS,"%s %s %s:
%s
]]>\n",
- UsrDat.FirstName,UsrDat.Surname1,UsrDat.Surname2,Content);
+ UsrDat.FrstName,UsrDat.Surname1,UsrDat.Surname2,Content);
/* Write author */
if (UsrDat.Email[0])
fprintf (FileRSS,"%s (%s %s %s)\n",
- UsrDat.Email,UsrDat.FirstName,UsrDat.Surname1,UsrDat.Surname2);
+ UsrDat.Email,UsrDat.FrstName,UsrDat.Surname1,UsrDat.Surname2);
/* Write unique string for this item */
fprintf (FileRSS,"%s, course #%ld, notice #%ld\n",
@@ -326,7 +322,6 @@ static void RSS_WriteExamAnnouncements (FILE *FileRSS,struct Crs_Course *Crs)
void RSS_BuildRSSLink (char RSSLink[Cns_MAX_BYTES_WWW + 1],long CrsCod)
{
- snprintf (RSSLink,Cns_MAX_BYTES_WWW + 1,
- "%s/%ld/%s/%s",
+ snprintf (RSSLink,Cns_MAX_BYTES_WWW + 1,"%s/%ld/%s/%s",
Cfg_URL_CRS_PUBLIC,CrsCod,Cfg_RSS_FOLDER,Cfg_RSS_FILE);
}
diff --git a/swad_account.c b/swad_account.c
index 3d92b733..37bc0bf8 100644
--- a/swad_account.c
+++ b/swad_account.c
@@ -83,9 +83,9 @@ extern struct Globals Gbl;
static void Acc_ShowFormCheckIfIHaveAccount (const char *Title);
static void Acc_WriteRowEmptyAccount (unsigned NumUsr,const char *ID,struct UsrData *UsrDat);
-static void Acc_ShowFormRequestNewAccountWithParams (const char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1],
+static void Acc_ShowFormRequestNewAccountWithParams (const char NewNickWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1],
const char *NewEmail);
-static bool Acc_GetParamsNewAccount (char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1],
+static bool Acc_GetParamsNewAccount (char NewNickWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1],
char *NewEmail,
char *NewEncryptedPassword);
static void Acc_CreateNewEncryptedUsrCod (struct UsrData *UsrDat);
@@ -313,7 +313,7 @@ static void Acc_WriteRowEmptyAccount (unsigned NumUsr,const char *ID,struct UsrD
/***** Button to login with this account *****/
HTM_TD_Begin ("class=\"RT COLOR%u\"",Gbl.RowEvenOdd);
Frm_StartForm (ActLogInNew);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
Btn_PutCreateButtonInline (Txt_Its_me);
Frm_EndForm ();
HTM_TD_End ();
@@ -353,7 +353,7 @@ void Acc_ShowFormCreateMyAccount (void)
/************ Show form to create a new account using parameters *************/
/*****************************************************************************/
-static void Acc_ShowFormRequestNewAccountWithParams (const char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1],
+static void Acc_ShowFormRequestNewAccountWithParams (const char NewNickWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1],
const char *NewEmail)
{
extern const char *Hlp_PROFILE_SignUp;
@@ -363,7 +363,7 @@ static void Acc_ShowFormRequestNewAccountWithParams (const char NewNicknameWitho
extern const char *Txt_HELP_nickname;
extern const char *Txt_HELP_email;
extern const char *Txt_Email;
- char NewNicknameWithArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
+ char NewNickWithArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
/***** Begin form to enter some data of the new user *****/
Frm_StartForm (ActCreUsrAcc);
@@ -374,12 +374,11 @@ static void Acc_ShowFormRequestNewAccountWithParams (const char NewNicknameWitho
Hlp_PROFILE_SignUp,Box_NOT_CLOSABLE,2);
/***** Nickname *****/
- if (NewNicknameWithoutArroba[0])
- snprintf (NewNicknameWithArroba,sizeof (NewNicknameWithArroba),
- "@%s",
- NewNicknameWithoutArroba);
+ if (NewNickWithoutArroba[0])
+ snprintf (NewNickWithArroba,sizeof (NewNickWithArroba),"@%s",
+ NewNickWithoutArroba);
else
- NewNicknameWithArroba[0] = '\0';
+ NewNickWithArroba[0] = '\0';
HTM_TR_Begin (NULL);
/* Label */
@@ -388,7 +387,7 @@ static void Acc_ShowFormRequestNewAccountWithParams (const char NewNicknameWitho
/* Data */
HTM_TD_Begin ("class=\"LT\"");
HTM_INPUT_TEXT ("NewNick",1 + Nck_MAX_CHARS_NICKNAME_WITHOUT_ARROBA,
- NewNicknameWithArroba,HTM_DONT_SUBMIT_ON_CHANGE,
+ NewNickWithArroba,HTM_DONT_SUBMIT_ON_CHANGE,
"id=\"NewNick\" size=\"18\" placeholder=\"%s\" required=\"required\"",
Txt_HELP_nickname);
HTM_TD_End ();
@@ -563,7 +562,7 @@ void Acc_PutLinkToRemoveMyAccount (__attribute__((unused)) void *Args)
if (Acc_CheckIfICanEliminateAccount (Gbl.Usrs.Me.UsrDat.UsrCod))
Lay_PutContextualLinkOnlyIcon (ActReqRemMyAcc,NULL,
- Acc_PutParamsToRemoveMyAccount,Gbl.Usrs.Me.UsrDat.EncryptedUsrCod,
+ Acc_PutParamsToRemoveMyAccount,Gbl.Usrs.Me.UsrDat.EnUsrCod,
"trash.svg",
Txt_Remove_account);
}
@@ -583,11 +582,11 @@ static void Acc_PutParamsToRemoveMyAccount (void *EncryptedUsrCod)
bool Acc_CreateMyNewAccountAndLogIn (void)
{
- char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
+ char NewNickWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
char NewEmail[Cns_MAX_BYTES_EMAIL_ADDRESS + 1];
char NewEncryptedPassword[Pwd_BYTES_ENCRYPTED_PASSWORD + 1];
- if (Acc_GetParamsNewAccount (NewNicknameWithoutArroba,NewEmail,NewEncryptedPassword))
+ if (Acc_GetParamsNewAccount (NewNickWithoutArroba,NewEmail,NewEncryptedPassword))
{
/***** User's has no ID *****/
Gbl.Usrs.Me.UsrDat.IDs.Num = 0;
@@ -595,23 +594,23 @@ bool Acc_CreateMyNewAccountAndLogIn (void)
/***** Set password to the password typed by the user *****/
Str_Copy (Gbl.Usrs.Me.UsrDat.Password,NewEncryptedPassword,
- Pwd_BYTES_ENCRYPTED_PASSWORD);
+ sizeof (Gbl.Usrs.Me.UsrDat.Password) - 1);
/***** User does not exist in the platform, so create him/her! *****/
Acc_CreateNewUsr (&Gbl.Usrs.Me.UsrDat,
true); // I am creating my own account
/***** Save nickname *****/
- Nck_UpdateNickInDB (Gbl.Usrs.Me.UsrDat.UsrCod,NewNicknameWithoutArroba);
- Str_Copy (Gbl.Usrs.Me.UsrDat.Nickname,NewNicknameWithoutArroba,
- Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA);
+ Nck_UpdateNickInDB (Gbl.Usrs.Me.UsrDat.UsrCod,NewNickWithoutArroba);
+ Str_Copy (Gbl.Usrs.Me.UsrDat.Nickname,NewNickWithoutArroba,
+ sizeof (Gbl.Usrs.Me.UsrDat.Nickname) - 1);
/***** Save email *****/
if (Mai_UpdateEmailInDB (&Gbl.Usrs.Me.UsrDat,NewEmail))
{
/* Email updated sucessfully */
Str_Copy (Gbl.Usrs.Me.UsrDat.Email,NewEmail,
- Cns_MAX_BYTES_EMAIL_ADDRESS);
+ sizeof (Gbl.Usrs.Me.UsrDat.Email) - 1);
Gbl.Usrs.Me.UsrDat.EmailConfirmed = false;
}
@@ -621,7 +620,7 @@ bool Acc_CreateMyNewAccountAndLogIn (void)
else
{
/***** Show form again ******/
- Acc_ShowFormRequestNewAccountWithParams (NewNicknameWithoutArroba,NewEmail);
+ Acc_ShowFormRequestNewAccountWithParams (NewNickWithoutArroba,NewEmail);
return false;
}
}
@@ -631,7 +630,7 @@ bool Acc_CreateMyNewAccountAndLogIn (void)
/*****************************************************************************/
// Return false on error
-static bool Acc_GetParamsNewAccount (char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1],
+static bool Acc_GetParamsNewAccount (char NewNickWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1],
char *NewEmail,
char *NewEncryptedPassword)
{
@@ -639,44 +638,43 @@ static bool Acc_GetParamsNewAccount (char NewNicknameWithoutArroba[Nck_MAX_BYTES
extern const char *Txt_The_nickname_entered_X_is_not_valid_;
extern const char *Txt_The_email_address_X_had_been_registered_by_another_user;
extern const char *Txt_The_email_address_entered_X_is_not_valid;
- char NewNicknameWithArroba[1 + Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
+ char NewNickWithArroba[1 + Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
char NewPlainPassword[Pwd_MAX_BYTES_PLAIN_PASSWORD + 1];
bool Error = false;
/***** Step 1/3: Get new nickname from form *****/
- Par_GetParToText ("NewNick",NewNicknameWithArroba,
+ Par_GetParToText ("NewNick",NewNickWithArroba,
Nck_MAX_BYTES_NICKNAME_FROM_FORM);
/* Remove arrobas at the beginning */
- Str_Copy (NewNicknameWithoutArroba,NewNicknameWithArroba,
+ Str_Copy (NewNickWithoutArroba,NewNickWithArroba,
Nck_MAX_BYTES_NICKNAME_FROM_FORM);
- Str_RemoveLeadingArrobas (NewNicknameWithoutArroba);
+ Str_RemoveLeadingArrobas (NewNickWithoutArroba);
/* Create a new version of the nickname with arroba */
- snprintf (NewNicknameWithArroba,sizeof (NewNicknameWithArroba),
- "@%s",
- NewNicknameWithoutArroba);
+ snprintf (NewNickWithArroba,sizeof (NewNickWithArroba),"@%s",
+ NewNickWithoutArroba);
- if (Nck_CheckIfNickWithArrobaIsValid (NewNicknameWithArroba)) // If new nickname is valid
+ if (Nck_CheckIfNickWithArrobaIsValid (NewNickWithArroba)) // If new nickname is valid
{
/* Check if the new nickname
matches any of the nicknames of other users */
if (DB_QueryCOUNT ("can not check if nickname already existed",
"SELECT COUNT(*) FROM usr_nicknames"
" WHERE Nickname='%s' AND UsrCod<>%ld",
- NewNicknameWithoutArroba,
+ NewNickWithoutArroba,
Gbl.Usrs.Me.UsrDat.UsrCod)) // A nickname of another user is the same that this nickname
{
Error = true;
Ale_ShowAlert (Ale_WARNING,Txt_The_nickname_X_had_been_registered_by_another_user,
- NewNicknameWithoutArroba);
+ NewNickWithoutArroba);
}
}
else // New nickname is not valid
{
Error = true;
Ale_ShowAlert (Ale_WARNING,Txt_The_nickname_entered_X_is_not_valid_,
- NewNicknameWithArroba,
+ NewNickWithArroba,
Nck_MIN_CHARS_NICKNAME_WITHOUT_ARROBA,
Nck_MAX_CHARS_NICKNAME_WITHOUT_ARROBA);
}
@@ -773,9 +771,9 @@ void Acc_CreateNewUsr (struct UsrData *UsrDat,bool CreatingMyOwnAccount)
"'%s','%s',"
"%s,'%s',"
"%u,%u,-1,0)",
- UsrDat->EncryptedUsrCod,
+ UsrDat->EnUsrCod,
UsrDat->Password,
- UsrDat->Surname1,UsrDat->Surname2,UsrDat->FirstName,
+ UsrDat->Surname1,UsrDat->Surname2,UsrDat->FrstName,
Usr_StringsSexDB[UsrDat->Sex],
The_ThemeId[UsrDat->Prefs.Theme],
Ico_IconSetId[UsrDat->Prefs.IconSet],
@@ -836,8 +834,8 @@ static void Acc_CreateNewEncryptedUsrCod (struct UsrData *UsrDat)
NumTry++)
{
Str_CreateRandomAlphanumStr (RandomStr,LENGTH_RANDOM_STR);
- Cry_EncryptSHA256Base64 (RandomStr,UsrDat->EncryptedUsrCod);
- if (!Usr_ChkIfEncryptedUsrCodExists (UsrDat->EncryptedUsrCod))
+ Cry_EncryptSHA256Base64 (RandomStr,UsrDat->EnUsrCod);
+ if (!Usr_ChkIfEncryptedUsrCodExists (UsrDat->EnUsrCod))
break;
}
if (NumTry == MAX_TRY)
@@ -985,7 +983,7 @@ static void Acc_AskIfRemoveOtherUsrAccount (void)
/* Show form to request confirmation */
Frm_StartForm (ActRemUsrGbl);
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
Pwd_AskForConfirmationOnDangerousAction ();
Btn_PutRemoveButton (Txt_Eliminate_user_account);
Frm_EndForm ();
diff --git a/swad_action.c b/swad_action.c
index 50233873..09adccdc 100644
--- a/swad_action.c
+++ b/swad_action.c
@@ -3965,8 +3965,7 @@ static const char *Act_GetActionTextFromDB (long ActCod) // TODO: Remove when da
{
/***** Get text *****/
row = mysql_fetch_row (mysql_res);
- Str_Copy (ActTxt,row[0],
- Act_MAX_BYTES_ACTION_TXT);
+ Str_Copy (ActTxt,row[0],sizeof (ActTxt) - 1);
}
else // ActCod-Language not found on database
ActTxt[0] = '\0';
@@ -4084,7 +4083,7 @@ void Act_AdjustCurrentAction (void)
the only action possible
is to show a form to change my shared record card *****/
if ( Gbl.Usrs.Me.UsrDat.Sex == Usr_SEX_UNKNOWN ||
- !Gbl.Usrs.Me.UsrDat.FirstName[0] ||
+ !Gbl.Usrs.Me.UsrDat.FrstName[0] ||
!Gbl.Usrs.Me.UsrDat.Surname1 [0] ||
Gbl.Usrs.Me.UsrDat.CtyCod <= 0 ||
Gbl.Usrs.Me.UsrDat.InsCod < 0 ||
diff --git a/swad_agenda.c b/swad_agenda.c
index ad13409a..94e1146a 100644
--- a/swad_agenda.c
+++ b/swad_agenda.c
@@ -170,9 +170,7 @@ void Agd_PutParamAgd (void)
{
char Nickname[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
- snprintf (Nickname,sizeof (Nickname),
- "@%s",
- Gbl.Usrs.Other.UsrDat.Nickname);
+ snprintf (Nickname,sizeof (Nickname),"@%s",Gbl.Usrs.Other.UsrDat.Nickname);
Par_PutHiddenParamString (NULL,"agd",Nickname);
}
@@ -411,12 +409,12 @@ void Agd_ShowUsrAgenda (void)
if (ItsMe)
Box_BoxBegin ("100%",Str_BuildStringStr (Txt_Public_agenda_USER,
Gbl.Usrs.Me.UsrDat.FullName),
- Agd_PutIconsMyPublicAgenda,Gbl.Usrs.Me.UsrDat.EncryptedUsrCod,
+ Agd_PutIconsMyPublicAgenda,Gbl.Usrs.Me.UsrDat.EnUsrCod,
Hlp_PROFILE_Agenda_public_agenda,Box_NOT_CLOSABLE);
else
Box_BoxBegin ("100%",Str_BuildStringStr (Txt_Public_agenda_USER,
Gbl.Usrs.Other.UsrDat.FullName),
- Agd_PutIconsOtherPublicAgenda,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,
+ Agd_PutIconsOtherPublicAgenda,Gbl.Usrs.Other.UsrDat.EnUsrCod,
Hlp_PROFILE_Agenda_public_agenda,Box_NOT_CLOSABLE);
Str_FreeString ();
@@ -463,12 +461,12 @@ void Agd_ShowOtherAgendaAfterLogIn (void)
if (ItsMe)
Box_BoxBegin ("100%",Str_BuildStringStr (Txt_Public_agenda_USER,
Gbl.Usrs.Me.UsrDat.FullName),
- Agd_PutIconToViewEditMyFullAgenda,Gbl.Usrs.Me.UsrDat.EncryptedUsrCod,
+ Agd_PutIconToViewEditMyFullAgenda,Gbl.Usrs.Me.UsrDat.EnUsrCod,
Hlp_PROFILE_Agenda_public_agenda,Box_NOT_CLOSABLE);
else
Box_BoxBegin ("100%",Str_BuildStringStr (Txt_Public_agenda_USER,
Gbl.Usrs.Other.UsrDat.FullName),
- Agd_PutIconsOtherPublicAgenda,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,
+ Agd_PutIconsOtherPublicAgenda,Gbl.Usrs.Other.UsrDat.EnUsrCod,
Hlp_PROFILE_Agenda_public_agenda,Box_NOT_CLOSABLE);
Str_FreeString ();
@@ -650,7 +648,7 @@ static void Agd_WriteHeaderListEvents (const struct Agd_Agenda *Agenda,
case Agd_ANOTHER_AGENDA_TODAY:
case Agd_ANOTHER_AGENDA:
Frm_StartForm (ActSeeUsrAgd);
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
Pag_PutHiddenParamPagNum (Pag_ANOTHER_AGENDA,Agenda->CurrentPage);
break;
}
@@ -723,10 +721,8 @@ static void Agd_PutIconToShowQR (void)
char URL[Cns_MAX_BYTES_WWW + 1];
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
- snprintf (URL,sizeof (URL),
- "%s/%s?agd=@%s",
- Cfg_URL_SWAD_CGI,
- Lan_STR_LANG_ID[Gbl.Prefs.Language],
+ snprintf (URL,sizeof (URL),"%s/%s?agd=@%s",
+ Cfg_URL_SWAD_CGI,Lan_STR_LANG_ID[Gbl.Prefs.Language],
Gbl.Usrs.Me.UsrDat.Nickname);
QR_PutLinkToPrintQRCode (ActPrnAgdQR,
QR_PutParamQRString,URL);
@@ -1047,9 +1043,9 @@ static void Agd_GetListEvents (struct Agd_Agenda *Agenda,
Agd_AgendaType_t AgendaType)
{
char *UsrSubQuery;
- char Past__FutureEventsSubQuery[Agd_MAX_BYTES_SUBQUERY];
- char PrivatPublicEventsSubQuery[Agd_MAX_BYTES_SUBQUERY];
- char HiddenVisiblEventsSubQuery[Agd_MAX_BYTES_SUBQUERY];
+ char Past__FutureEventsSubQuery[Agd_MAX_BYTES_SUBQUERY + 1];
+ char PrivatPublicEventsSubQuery[Agd_MAX_BYTES_SUBQUERY + 1];
+ char HiddenVisiblEventsSubQuery[Agd_MAX_BYTES_SUBQUERY + 1];
static const char *OrderBySubQuery[Dat_NUM_START_END_TIME] =
{
[Dat_START_TIME] = "StartTime,EndTime,Event,Location",
@@ -1083,19 +1079,19 @@ static void Agd_GetListEvents (struct Agd_Agenda *Agenda,
Str_Copy (Past__FutureEventsSubQuery,
" AND DATE(StartTime)<=CURDATE()"
" AND DATE(EndTime)>=CURDATE()",
- Agd_MAX_BYTES_SUBQUERY); // Today events
+ sizeof (Past__FutureEventsSubQuery) - 1); // Today events
else
switch (Agenda->Past__FutureEvents)
{
case (1 << Agd_PAST___EVENTS):
Str_Copy (Past__FutureEventsSubQuery,
" AND DATE(StartTime)<=CURDATE()",
- Agd_MAX_BYTES_SUBQUERY); // Past and today events
+ sizeof (Past__FutureEventsSubQuery) - 1); // Past and today events
break;
case (1 << Agd_FUTURE_EVENTS):
Str_Copy (Past__FutureEventsSubQuery,
" AND DATE(EndTime)>=CURDATE()",
- Agd_MAX_BYTES_SUBQUERY); // Today and future events
+ sizeof (Past__FutureEventsSubQuery) - 1); // Today and future events
break;
default:
Past__FutureEventsSubQuery[0] = '\0'; // All events
@@ -1105,11 +1101,11 @@ static void Agd_GetListEvents (struct Agd_Agenda *Agenda,
{
case (1 << Agd_PRIVAT_EVENTS):
Str_Copy (PrivatPublicEventsSubQuery," AND Public='N'",
- Agd_MAX_BYTES_SUBQUERY); // Private events
+ sizeof (PrivatPublicEventsSubQuery) - 1); // Private events
break;
case (1 << Agd_PUBLIC_EVENTS):
Str_Copy (PrivatPublicEventsSubQuery," AND Public='Y'",
- Agd_MAX_BYTES_SUBQUERY); // Public events
+ sizeof (PrivatPublicEventsSubQuery) - 1); // Public events
break;
default:
PrivatPublicEventsSubQuery[0] = '\0'; // All events
@@ -1119,11 +1115,11 @@ static void Agd_GetListEvents (struct Agd_Agenda *Agenda,
{
case (1 << Agd_HIDDEN_EVENTS):
Str_Copy (HiddenVisiblEventsSubQuery," AND Hidden='Y'",
- Agd_MAX_BYTES_SUBQUERY); // Hidden events
+ sizeof (HiddenVisiblEventsSubQuery) - 1); // Hidden events
break;
case (1 << Agd_VISIBL_EVENTS):
Str_Copy (HiddenVisiblEventsSubQuery," AND Hidden='N'",
- Agd_MAX_BYTES_SUBQUERY); // Visible events
+ sizeof (HiddenVisiblEventsSubQuery) - 1); // Visible events
break;
default:
HiddenVisiblEventsSubQuery[0] = '\0'; // All events
@@ -1140,15 +1136,15 @@ static void Agd_GetListEvents (struct Agd_Agenda *Agenda,
Str_Copy (Past__FutureEventsSubQuery,
" AND DATE(StartTime)<=CURDATE()"
" AND DATE(EndTime)>=CURDATE()",
- Agd_MAX_BYTES_SUBQUERY); // Today events
+ sizeof (Past__FutureEventsSubQuery) - 1); // Today events
else
Str_Copy (Past__FutureEventsSubQuery,
" AND DATE(EndTime)>=CURDATE()",
- Agd_MAX_BYTES_SUBQUERY); // Today and future events
+ sizeof (Past__FutureEventsSubQuery) - 1); // Today and future events
Str_Copy (PrivatPublicEventsSubQuery," AND Public='Y'",
- Agd_MAX_BYTES_SUBQUERY); // Public events
+ sizeof (PrivatPublicEventsSubQuery) - 1); // Public events
Str_Copy (HiddenVisiblEventsSubQuery," AND Hidden='N'",
- Agd_MAX_BYTES_SUBQUERY); // Visible events
+ sizeof (HiddenVisiblEventsSubQuery) - 1); // Visible events
}
if (DoQuery)
@@ -1172,7 +1168,8 @@ static void Agd_GetListEvents (struct Agd_Agenda *Agenda,
Agenda->Num = (unsigned) NumRows;
/***** Create list of events *****/
- if ((Agenda->LstAgdCods = (long *) calloc (NumRows,sizeof (long))) == NULL)
+ if ((Agenda->LstAgdCods = calloc (NumRows,
+ sizeof (*Agenda->LstAgdCods))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the events codes *****/
@@ -1251,12 +1248,10 @@ static void Agd_GetDataOfEventByCod (struct Agd_Event *AgdEvent)
Dat_PRESENT));
/* Get the event (row[7]) */
- Str_Copy (AgdEvent->Event,row[7],
- Agd_MAX_BYTES_EVENT);
+ Str_Copy (AgdEvent->Event ,row[7],sizeof (AgdEvent->Event ) - 1);
/* Get the event (row[8]) */
- Str_Copy (AgdEvent->Location,row[8],
- Agd_MAX_BYTES_LOCATION);
+ Str_Copy (AgdEvent->Location,row[8],sizeof (AgdEvent->Location) - 1);
}
else
{
@@ -1313,8 +1308,7 @@ static void Agd_GetEventTxtFromDB (struct Agd_Event *AgdEvent,
{
/* Get info text */
row = mysql_fetch_row (mysql_res);
- Str_Copy (Txt,row[0],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Txt,row[0],Cns_MAX_BYTES_TEXT);
}
else
Txt[0] = '\0';
diff --git a/swad_announcement.c b/swad_announcement.c
index b3411aae..6d4fa202 100644
--- a/swad_announcement.c
+++ b/swad_announcement.c
@@ -156,12 +156,10 @@ void Ann_ShowAllAnnouncements (void)
Lay_ShowErrorAndExit ("Error when reading roles of announcement.");
/* Get the content (row[3]) */
- Str_Copy (Subject,row[3],
- Cns_MAX_BYTES_SUBJECT);
+ Str_Copy (Subject,row[3],sizeof (Subject) - 1);
/* Get the content (row[4]) and insert links */
- Str_Copy (Content,row[4],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Content,row[4],sizeof (Content) - 1);
Str_InsertLinks (Content,Cns_MAX_BYTES_TEXT,50);
/* Show the announcement */
@@ -248,12 +246,10 @@ void Ann_ShowMyAnnouncementsNotMarkedAsSeen (void)
Lay_ShowErrorAndExit ("Wrong code of announcement.");
/* Get the content (row[1]) */
- Str_Copy (Subject,row[1],
- Cns_MAX_BYTES_SUBJECT);
+ Str_Copy (Subject,row[1],sizeof (Subject) - 1);
/* Get the content (row[2]) and insert links */
- Str_Copy (Content,row[2],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Content,row[2],sizeof (Content) - 1);
Str_InsertLinks (Content,Cns_MAX_BYTES_TEXT,50);
/* Show the announcement */
diff --git a/swad_assignment.c b/swad_assignment.c
index 5cc574d0..b374a43e 100644
--- a/swad_assignment.c
+++ b/swad_assignment.c
@@ -543,8 +543,9 @@ static void Asg_WriteAssignmentFolder (struct Asg_Assignment *Asg,bool PrintView
case Rol_TCH:
case Rol_SYS_ADM:
Gbl.FileBrowser.Type = Brw_ADMI_ASG_CRS; // Course assignments
- Str_Copy (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,Gbl.Usrs.Me.UsrDat.EncryptedUsrCod,
- Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
+ Str_Copy (Gbl.Usrs.Other.UsrDat.EnUsrCod,
+ Gbl.Usrs.Me.UsrDat.EnUsrCod,
+ sizeof (Gbl.Usrs.Other.UsrDat.EnUsrCod) - 1);
Usr_CreateListSelectedUsrsCodsAndFillWithOtherUsr (&Gbl.Usrs.Selected);
Frm_StartForm (ActFrmCreAsgCrs);
break;
@@ -552,10 +553,11 @@ static void Asg_WriteAssignmentFolder (struct Asg_Assignment *Asg,bool PrintView
Rol_WrongRoleExit ();
break;
}
- Str_Copy (Gbl.FileBrowser.FilFolLnk.Path,Brw_INTERNAL_NAME_ROOT_FOLDER_ASSIGNMENTS,
- PATH_MAX);
+ Str_Copy (Gbl.FileBrowser.FilFolLnk.Path,
+ Brw_INTERNAL_NAME_ROOT_FOLDER_ASSIGNMENTS,
+ sizeof (Gbl.FileBrowser.FilFolLnk.Path) - 1);
Str_Copy (Gbl.FileBrowser.FilFolLnk.Name,Asg->Folder,
- NAME_MAX);
+ sizeof (Gbl.FileBrowser.FilFolLnk.Name) - 1);
Gbl.FileBrowser.FilFolLnk.Type = Brw_IS_FOLDER;
Brw_PutImplicitParamsFileBrowser (&Gbl.FileBrowser.FilFolLnk);
Ico_PutIconLink ("folder-open-yellow-plus.png",
@@ -720,7 +722,8 @@ static void Asg_GetListAssignments (struct Asg_Assignments *Assignments)
Assignments->Num = (unsigned) NumRows;
/***** Create list of assignments *****/
- if ((Assignments->LstAsgCods = (long *) calloc (NumRows,sizeof (long))) == NULL)
+ if ((Assignments->LstAsgCods = calloc (NumRows,
+ sizeof (*Assignments->LstAsgCods))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the assignments codes *****/
@@ -863,12 +866,10 @@ static void Asg_GetDataOfAssignment (struct Asg_Assignment *Asg,
Asg->Open = (row[5][0] == '1');
/* Get the title of the assignment (row[6]) */
- Str_Copy (Asg->Title,row[6],
- Asg_MAX_BYTES_ASSIGNMENT_TITLE);
+ Str_Copy (Asg->Title ,row[6],sizeof (Asg->Title ) - 1);
/* Get the folder for the assignment files (row[7]) */
- Str_Copy (Asg->Folder,row[7],
- Brw_MAX_BYTES_FOLDER);
+ Str_Copy (Asg->Folder,row[7],sizeof (Asg->Folder) - 1);
Asg->SendWork = (Asg->Folder[0] != '\0');
/* Can I do this assignment? */
@@ -937,8 +938,7 @@ static void Asg_GetAssignmentTxtFromDB (long AsgCod,char Txt[Cns_MAX_BYTES_TEXT
{
/* Get info text */
row = mysql_fetch_row (mysql_res);
- Str_Copy (Txt,row[0],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Txt,row[0],Cns_MAX_BYTES_TEXT);
}
else
Txt[0] = '\0';
@@ -979,17 +979,15 @@ void Asg_GetNotifAssignment (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
row = mysql_fetch_row (mysql_res);
/***** Get summary *****/
- Str_Copy (SummaryStr,row[0],
- Ntf_MAX_BYTES_SUMMARY);
+ Str_Copy (SummaryStr,row[0],Ntf_MAX_BYTES_SUMMARY);
/***** Get content *****/
if (GetContent)
{
Length = strlen (row[1]);
- if ((*ContentStr = (char *) malloc (Length + 1)) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for notification content.");
- Str_Copy (*ContentStr,row[1],
- Length);
+ if ((*ContentStr = malloc (Length + 1)) == NULL)
+ Lay_NotEnoughMemoryExit ();
+ Str_Copy (*ContentStr,row[1],Length);
}
}
diff --git a/swad_attendance.c b/swad_attendance.c
index 0a5980ef..12ebd7c3 100644
--- a/swad_attendance.c
+++ b/swad_attendance.c
@@ -371,7 +371,7 @@ static void Att_PutIconsInListOfAttEvents (void *Events)
/***** Put icon to print my QR code *****/
QR_PutLinkToPrintQRCode (ActPrnUsrQR,
- Usr_PutParamMyUsrCodEncrypted,Gbl.Usrs.Me.UsrDat.EncryptedUsrCod);
+ Usr_PutParamMyUsrCodEncrypted,Gbl.Usrs.Me.UsrDat.EnUsrCod);
}
}
@@ -705,7 +705,7 @@ static void Att_GetListAttEvents (struct Att_Events *Events,
Events->Num = (unsigned) NumRows;
/***** Create list of attendance events *****/
- if ((Events->Lst = (struct Att_Event *) calloc (NumRows,sizeof (struct Att_Event))) == NULL)
+ if ((Events->Lst = calloc (NumRows,sizeof (*Events->Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the attendance events codes *****/
@@ -804,8 +804,7 @@ bool Att_GetDataOfAttEventByCod (struct Att_Event *Event)
Event->CommentTchVisible = (row[7][0] == 'Y');
/* Get the title of the attendance event (row[8]) */
- Str_Copy (Event->Title,row[8],
- Att_MAX_BYTES_ATTENDANCE_EVENT_TITLE);
+ Str_Copy (Event->Title,row[8],sizeof (Event->Title) - 1);
}
/***** Free structure that stores the query result *****/
@@ -877,8 +876,7 @@ static void Att_GetAttEventDescriptionFromDB (long AttCod,char Description[Cns_M
row = mysql_fetch_row (mysql_res);
/* Get info text */
- Str_Copy (Description,row[0],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Description,row[0],Cns_MAX_BYTES_TEXT);
}
else
Description[0] = '\0';
@@ -2128,7 +2126,7 @@ static void Att_WriteRowUsrToCallTheRoll (unsigned NumUsr,
HTM_TD_Begin ("class=\"CT COLOR%u\"",Gbl.RowEvenOdd);
HTM_INPUT_CHECKBOX ("UsrCodStd",HTM_DONT_SUBMIT_ON_CHANGE,
"id=\"Std%u\" value=\"%s\"%s%s",
- NumUsr,UsrDat->EncryptedUsrCod,
+ NumUsr,UsrDat->EnUsrCod,
Present ? " checked=\"checked\"" : "",
ICanChangeStdAttendance ? "" : " disabled=\"disabled\"");
HTM_TD_End ();
@@ -2168,7 +2166,7 @@ static void Att_WriteRowUsrToCallTheRoll (unsigned NumUsr,
HTM_Txt (UsrDat->Surname1);
if (UsrDat->Surname2[0])
HTM_TxtF (" %s",UsrDat->Surname2);
- HTM_TxtF (", %s",UsrDat->FirstName);
+ HTM_TxtF (", %s",UsrDat->FrstName);
HTM_TD_End ();
/***** Student's comment: write form or text */
@@ -2176,7 +2174,7 @@ static void Att_WriteRowUsrToCallTheRoll (unsigned NumUsr,
if (ICanEditStdComment) // Show with form
{
HTM_TEXTAREA_Begin ("name=\"CommentStd%s\" cols=\"40\" rows=\"3\"",
- UsrDat->EncryptedUsrCod);
+ UsrDat->EnUsrCod);
HTM_Txt (CommentStd);
HTM_TEXTAREA_End ();
}
@@ -2193,7 +2191,7 @@ static void Att_WriteRowUsrToCallTheRoll (unsigned NumUsr,
if (ICanEditTchComment) // Show with form
{
HTM_TEXTAREA_Begin ("name=\"CommentTch%s\" cols=\"40\" rows=\"3\"",
- UsrDat->EncryptedUsrCod);
+ UsrDat->EnUsrCod);
HTM_Txt (CommentTch);
HTM_TEXTAREA_End ();
}
@@ -2253,7 +2251,7 @@ static void Att_PutParamsCodGrps (long AttCod)
if (NumGrps) // Groups found...
{
MaxLengthGrpCods = NumGrps * (1 + 20) - 1;
- if ((GrpCods = (char *) malloc (MaxLengthGrpCods + 1)) == NULL)
+ if ((GrpCods = malloc (MaxLengthGrpCods + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
GrpCods[0] = '\0';
@@ -2310,7 +2308,7 @@ void Att_RegisterMeAsStdInAttEvent (void)
Present = Att_CheckIfUsrIsPresentInAttEventAndGetComments (Event.AttCod,Gbl.Usrs.Me.UsrDat.UsrCod,
CommentStd,CommentTch);
Par_GetParToHTML (Str_BuildStringStr ("CommentStd%s",
- Gbl.Usrs.Me.UsrDat.EncryptedUsrCod),
+ Gbl.Usrs.Me.UsrDat.EnUsrCod),
CommentStd,Cns_MAX_BYTES_TEXT);
Str_FreeString ();
@@ -2396,7 +2394,7 @@ void Att_RegisterStudentsInAttEvent (void)
Ptr = Gbl.Usrs.Selected.List[Rol_STD];
while (*Ptr)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,UsrData.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,UsrData.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrData);
if (UsrData.UsrCod > 0) // Student exists in database
@@ -2427,7 +2425,7 @@ void Att_RegisterStudentsInAttEvent (void)
/***** Get comments for this student *****/
Att_CheckIfUsrIsPresentInAttEventAndGetComments (Event.AttCod,Gbl.Usrs.LstUsrs[Rol_STD].Lst[NumUsr].UsrCod,CommentStd,CommentTch);
Par_GetParToHTML (Str_BuildStringStr ("CommentTch%s",
- Gbl.Usrs.LstUsrs[Rol_STD].Lst[NumUsr].EncryptedUsrCod),
+ Gbl.Usrs.LstUsrs[Rol_STD].Lst[NumUsr].EnUsrCod),
CommentTch,Cns_MAX_BYTES_TEXT);
Str_FreeString ();
@@ -2603,12 +2601,10 @@ static bool Att_CheckIfUsrIsPresentInAttEventAndGetComments (long AttCod,long Us
Present = (row[0][0] == 'Y');
/* Get student's comment (row[1]) */
- Str_Copy (CommentStd,row[1],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (CommentStd,row[1],Cns_MAX_BYTES_TEXT);
/* Get teacher's comment (row[2]) */
- Str_Copy (CommentTch,row[2],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (CommentTch,row[2],Cns_MAX_BYTES_TEXT);
}
else // User is not present
{
@@ -2977,7 +2973,7 @@ static void Att_GetListSelectedAttCods (struct Att_Events *Events)
/***** Allocate memory for list of attendance events selected *****/
MaxSizeListAttCodsSelected = (size_t) Events->Num * (Cns_MAX_DECIMAL_DIGITS_LONG + 1);
- if ((Events->StrAttCodsSelected = (char *) malloc (MaxSizeListAttCodsSelected + 1)) == NULL)
+ if ((Events->StrAttCodsSelected = malloc (MaxSizeListAttCodsSelected + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get parameter multiple with list of attendance events selected *****/
@@ -3083,7 +3079,7 @@ static void Att_PutIconsMyAttList (void *Events)
/***** Put icon to print my QR code *****/
QR_PutLinkToPrintQRCode (ActPrnUsrQR,
- Usr_PutParamMyUsrCodEncrypted,Gbl.Usrs.Me.UsrDat.EncryptedUsrCod);
+ Usr_PutParamMyUsrCodEncrypted,Gbl.Usrs.Me.UsrDat.EnUsrCod);
}
}
@@ -3113,7 +3109,7 @@ static void Att_PutIconsStdsAttList (void *Events)
/***** Put icon to print my QR code *****/
QR_PutLinkToPrintQRCode (ActPrnUsrQR,
- Usr_PutParamMyUsrCodEncrypted,Gbl.Usrs.Me.UsrDat.EncryptedUsrCod);
+ Usr_PutParamMyUsrCodEncrypted,Gbl.Usrs.Me.UsrDat.EnUsrCod);
}
}
@@ -3422,9 +3418,7 @@ static void Att_WriteTableHeadSeveralAttEvents (const struct Att_Events *Events)
/***** Put link to this attendance event *****/
HTM_TH_Begin (1,1,"CM");
- snprintf (StrNumAttEvent,sizeof (StrNumAttEvent),
- "%u",
- NumAttEvent + 1);
+ snprintf (StrNumAttEvent,sizeof (StrNumAttEvent),"%u",NumAttEvent + 1);
Att_PutLinkAttEvent (&Events->Lst[NumAttEvent],
Events->Lst[NumAttEvent].Title,
StrNumAttEvent,
@@ -3487,7 +3481,7 @@ static void Att_WriteRowUsrSeveralAttEvents (const struct Att_Events *Events,
HTM_Txt (UsrDat->Surname1);
if (UsrDat->Surname2[0])
HTM_TxtF (" %s",UsrDat->Surname2);
- HTM_TxtF (", %s",UsrDat->FirstName);
+ HTM_TxtF (", %s",UsrDat->FrstName);
HTM_TD_End ();
/***** Check/cross to show if the user is present/absent *****/
@@ -3646,7 +3640,7 @@ static void Att_ListAttEventsForAStd (const struct Att_Events *Events,
HTM_Txt (UsrDat->Surname1);
if (UsrDat->Surname2[0])
HTM_TxtF (" %s",UsrDat->Surname2);
- HTM_TxtF (", %s",UsrDat->FirstName);
+ HTM_TxtF (", %s",UsrDat->FrstName);
HTM_TD_End ();
HTM_TR_End ();
diff --git a/swad_banner.c b/swad_banner.c
index e126ac47..26fc6c2a 100644
--- a/swad_banner.c
+++ b/swad_banner.c
@@ -297,8 +297,7 @@ static void Ban_GetListBanners (struct Ban_Banners *Banners,
Banners->Num = (unsigned) NumRows;
/***** Create list with banners *****/
- if ((Banners->Lst = (struct Ban_Banner *)
- calloc (NumRows,sizeof (struct Ban_Banner))) == NULL)
+ if ((Banners->Lst = calloc (NumRows,sizeof (*Banners->Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the banners *****/
@@ -319,20 +318,16 @@ static void Ban_GetListBanners (struct Ban_Banners *Banners,
Ban->Hidden = (row[1][0] == 'Y');
/* Get the short name of the banner (row[2]) */
- Str_Copy (Ban->ShrtName,row[2],
- Ban_MAX_BYTES_SHRT_NAME);
+ Str_Copy (Ban->ShrtName,row[2],sizeof (Ban->ShrtName) - 1);
/* Get the full name of the banner (row[3]) */
- Str_Copy (Ban->FullName,row[3],
- Ban_MAX_BYTES_FULL_NAME);
+ Str_Copy (Ban->FullName,row[3],sizeof (Ban->FullName) - 1);
/* Get the image of the banner (row[4]) */
- Str_Copy (Ban->Img,row[4],
- Ban_MAX_BYTES_IMAGE);
+ Str_Copy (Ban->Img ,row[4],sizeof (Ban->Img ) - 1);
/* Get the URL of the banner (row[5]) */
- Str_Copy (Ban->WWW,row[5],
- Cns_MAX_BYTES_WWW);
+ Str_Copy (Ban->WWW ,row[5],sizeof (Ban->WWW ) - 1);
}
}
else
@@ -373,20 +368,16 @@ void Ban_GetDataOfBannerByCod (struct Ban_Banner *Ban)
Ban->Hidden = (row[0][0] == 'Y');
/* Get the short name of the banner (row[1]) */
- Str_Copy (Ban->ShrtName,row[1],
- Ban_MAX_BYTES_SHRT_NAME);
+ Str_Copy (Ban->ShrtName,row[1],sizeof (Ban->ShrtName) - 1);
/* Get the full name of the banner (row[2]) */
- Str_Copy (Ban->FullName,row[2],
- Ban_MAX_BYTES_FULL_NAME);
+ Str_Copy (Ban->FullName,row[2],sizeof (Ban->FullName) - 1);
/* Get the image of the banner (row[3]) */
- Str_Copy (Ban->Img,row[3],
- Ban_MAX_BYTES_IMAGE);
+ Str_Copy (Ban->Img ,row[3],sizeof (Ban->Img ) - 1);
/* Get the URL of the banner (row[4]) */
- Str_Copy (Ban->WWW,row[4],
- Cns_MAX_BYTES_WWW);
+ Str_Copy (Ban->WWW ,row[4],sizeof (Ban->WWW ) - 1);
}
/***** Free structure that stores the query result *****/
@@ -767,8 +758,7 @@ static void Ban_RenameBanner (struct Ban_Banner *Ban,
}
/***** Update name *****/
- Str_Copy (CurrentBanName,NewBanName,
- MaxBytes);
+ Str_Copy (CurrentBanName,NewBanName,MaxBytes);
}
/*****************************************************************************/
@@ -841,8 +831,7 @@ void Ban_ChangeBannerImg (void)
Txt_You_can_not_leave_the_image_empty);
/***** Update image *****/
- Str_Copy (Ban.Img,NewImg,
- Ban_MAX_BYTES_IMAGE);
+ Str_Copy (Ban.Img,NewImg,sizeof (Ban.Img) - 1);
/***** Set editing banner to use ot in a posterior function *****/
Ban_SetEditingBanner (&Ban);
@@ -889,8 +878,7 @@ void Ban_ChangeBannerWWW (void)
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
/***** Update web *****/
- Str_Copy (Ban.WWW,NewWWW,
- Cns_MAX_BYTES_WWW);
+ Str_Copy (Ban.WWW,NewWWW,sizeof (Ban.WWW) - 1);
/***** Set editing banner to use ot in a posterior function *****/
Ban_SetEditingBanner (&Ban);
diff --git a/swad_box.c b/swad_box.c
index 1fc26a49..e0e9905b 100644
--- a/swad_box.c
+++ b/swad_box.c
@@ -132,8 +132,8 @@ static void Box_BoxInternalBegin (const char *Width,const char *Title,
/***** Create unique identifier for this box *****/
if (Closable == Box_CLOSABLE)
{
- if ((Gbl.Box.Ids[Gbl.Box.Nested] = (char *) malloc (Frm_MAX_BYTES_ID + 1)) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for box id.");
+ if ((Gbl.Box.Ids[Gbl.Box.Nested] = malloc (Frm_MAX_BYTES_ID + 1)) == NULL)
+ Lay_NotEnoughMemoryExit ();
}
else
Gbl.Box.Ids[Gbl.Box.Nested] = NULL;
diff --git a/swad_building.c b/swad_building.c
index 9b796d8a..c0b4ccd3 100644
--- a/swad_building.c
+++ b/swad_building.c
@@ -355,9 +355,7 @@ void Bld_GetListBuildings (struct Bld_Buildings *Buildings,
Buildings->Num = (unsigned) NumRows;
/***** Create list with courses in centre *****/
- if ((Buildings->Lst = (struct Bld_Building *)
- calloc (NumRows,
- sizeof (struct Bld_Building))) == NULL)
+ if ((Buildings->Lst = calloc (NumRows,sizeof (*Buildings->Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the buildings *****/
@@ -375,18 +373,17 @@ void Bld_GetListBuildings (struct Bld_Buildings *Buildings,
Lay_ShowErrorAndExit ("Wrong code of building.");
/* Get the short name of the building (row[1]) */
- Str_Copy (Building->ShrtName,row[1],
- Bld_MAX_BYTES_SHRT_NAME);
+ Str_Copy (Building->ShrtName,row[1],sizeof (Building->ShrtName) - 1);
if (WhichData == Bld_ALL_DATA)
{
/* Get the full name of the building (row[2]) */
Str_Copy (Building->FullName,row[2],
- Bld_MAX_BYTES_FULL_NAME);
+ sizeof (Building->FullName) - 1);
/* Get the full name of the building (row[3]) */
Str_Copy (Building->Location,row[3],
- Bld_MAX_BYTES_LOCATION);
+ sizeof (Building->Location) - 1);
}
}
}
@@ -431,16 +428,13 @@ void Bld_GetDataOfBuildingByCod (struct Bld_Building *Building)
row = mysql_fetch_row (mysql_res);
/* Get the short name of the building (row[0]) */
- Str_Copy (Building->ShrtName,row[0],
- Bld_MAX_BYTES_SHRT_NAME);
+ Str_Copy (Building->ShrtName,row[0],sizeof (Building->ShrtName) - 1);
/* Get the full name of the building (row[1]) */
- Str_Copy (Building->FullName,row[1],
- Bld_MAX_BYTES_FULL_NAME);
+ Str_Copy (Building->FullName,row[1],sizeof (Building->FullName) - 1);
/* Get the location of the building (row[2]) */
- Str_Copy (Building->Location,row[2],
- Bld_MAX_BYTES_LOCATION);
+ Str_Copy (Building->Location,row[2],sizeof (Building->Location) - 1);
}
/***** Free structure that stores the query result *****/
@@ -709,8 +703,7 @@ static void Bld_RenameBuilding (Cns_ShrtOrFullName_t ShrtOrFullName)
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
/***** Update building name *****/
- Str_Copy (CurrentClaName,NewClaName,
- MaxBytes);
+ Str_Copy (CurrentClaName,NewClaName,MaxBytes);
}
/*****************************************************************************/
@@ -772,7 +765,7 @@ void Bld_ChangeBuildingLocation (void)
/* Update the table changing old name by new name */
Bld_UpdateBuildingNameDB (Bld_EditingBuilding->BldCod,"Location",NewLocation);
Str_Copy (Bld_EditingBuilding->Location,NewLocation,
- Bld_MAX_BYTES_LOCATION);
+ sizeof (Bld_EditingBuilding->Location) - 1);
/* Write message to show the change made */
Ale_CreateAlert (Ale_SUCCESS,NULL,
@@ -958,8 +951,8 @@ static void Bld_EditingBuildingConstructor (void)
Lay_ShowErrorAndExit ("Error initializing building.");
/***** Allocate memory for building *****/
- if ((Bld_EditingBuilding = (struct Bld_Building *) malloc (sizeof (struct Bld_Building))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for building.");
+ if ((Bld_EditingBuilding = malloc (sizeof (*Bld_EditingBuilding))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/***** Reset building *****/
Bld_EditingBuilding->BldCod = -1L;
diff --git a/swad_calendar.c b/swad_calendar.c
index 2c4a9b42..2c1e42f9 100644
--- a/swad_calendar.c
+++ b/swad_calendar.c
@@ -128,9 +128,7 @@ void Cal_ShowFormToSelFirstDayOfWeek (Act_Action_t Action,
Par_PutHiddenParamUnsigned (NULL,"FirstDayOfWeek",FirstDayOfWeek);
if (FuncParams) // Extra parameters depending on the action
FuncParams (Args);
- snprintf (Icon,sizeof (Icon),
- "first-day-of-week-%u.png",
- FirstDayOfWeek);
+ snprintf (Icon,sizeof (Icon),"first-day-of-week-%u.png",FirstDayOfWeek);
Ico_PutSettingIconLink (Icon,
Str_BuildStringStr (Txt_First_day_of_the_week_X,
Txt_DAYS_SMALL[FirstDayOfWeek]));
diff --git a/swad_centre.c b/swad_centre.c
index 00400529..962eb429 100644
--- a/swad_centre.c
+++ b/swad_centre.c
@@ -571,8 +571,8 @@ void Ctr_GetBasicListOfCentres (long InsCod)
Gbl.Hierarchy.Ctrs.Num = (unsigned) NumRows;
/***** Create list with courses in degree *****/
- if ((Gbl.Hierarchy.Ctrs.Lst = (struct Ctr_Centre *) calloc (NumRows,
- sizeof (struct Ctr_Centre))) == NULL)
+ if ((Gbl.Hierarchy.Ctrs.Lst = calloc (NumRows,
+ sizeof (*Gbl.Hierarchy.Ctrs.Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the centres *****/
@@ -660,8 +660,8 @@ void Ctr_GetFullListOfCentres (long InsCod)
Gbl.Hierarchy.Ctrs.Num = (unsigned) NumRows;
/***** Create list with courses in degree *****/
- if ((Gbl.Hierarchy.Ctrs.Lst = (struct Ctr_Centre *) calloc (NumRows,
- sizeof (struct Ctr_Centre))) == NULL)
+ if ((Gbl.Hierarchy.Ctrs.Lst = calloc (NumRows,
+ sizeof (*Gbl.Hierarchy.Ctrs.Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the centres *****/
@@ -778,16 +778,13 @@ static void Ctr_GetDataOfCentreFromRow (struct Ctr_Centre *Ctr,MYSQL_ROW row)
Ctr->Coord.Altitude = Map_GetAltitudeFromStr (row[7]);
/***** Get the short name of the centre (row[8]) *****/
- Str_Copy (Ctr->ShrtName,row[8],
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ Str_Copy (Ctr->ShrtName,row[8],sizeof (Ctr->ShrtName) - 1);
/***** Get the full name of the centre (row[9]) *****/
- Str_Copy (Ctr->FullName,row[9],
- Cns_HIERARCHY_MAX_BYTES_FULL_NAME);
+ Str_Copy (Ctr->FullName,row[9],sizeof (Ctr->FullName) - 1);
/***** Get the URL of the centre (row[10]) *****/
- Str_Copy (Ctr->WWW,row[10],
- Cns_MAX_BYTES_WWW);
+ Str_Copy (Ctr->WWW,row[10],sizeof (Ctr->WWW) - 1);
}
/*****************************************************************************/
@@ -840,8 +837,7 @@ void Ctr_GetShortNameOfCentreByCod (struct Ctr_Centre *Ctr)
/***** Get the short name of this centre *****/
row = mysql_fetch_row (mysql_res);
- Str_Copy (Ctr->ShrtName,row[0],
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ Str_Copy (Ctr->ShrtName,row[0],sizeof (Ctr->ShrtName) - 1);
}
/***** Free structure that stores the query result *****/
@@ -1064,8 +1060,7 @@ static void Ctr_ListCentresForEdition (const struct Plc_Places *Places)
}
else
{
- Str_Copy (WWW,Ctr->WWW,
- Cns_MAX_BYTES_WWW);
+ Str_Copy (WWW,Ctr->WWW,sizeof (WWW) - 1);
HTM_DIV_Begin ("class=\"EXTERNAL_WWW_SHORT\"");
HTM_A_Begin ("href=\"%s\" target=\"_blank\""
" class=\"DAT\" title=\"%s\"",Ctr->WWW,Ctr->WWW);
@@ -1266,11 +1261,10 @@ void Ctr_RemoveCentre (void)
Roo_RemoveAllRoomsInCtr (Ctr_EditingCtr->CtrCod);
/***** Remove directories of the centre *****/
- snprintf (PathCtr,sizeof (PathCtr),
- "%s/%02u/%u",
+ snprintf (PathCtr,sizeof (PathCtr),"%s/%02u/%u",
Cfg_PATH_CTR_PUBLIC,
(unsigned) (Ctr_EditingCtr->CtrCod % 100),
- (unsigned) Ctr_EditingCtr->CtrCod);
+ (unsigned) Ctr_EditingCtr->CtrCod);
Fil_RemoveTree (PathCtr);
/***** Remove centre *****/
@@ -1421,8 +1415,7 @@ void Ctr_RenameCentre (struct Ctr_Centre *Ctr,Cns_ShrtOrFullName_t ShrtOrFullNam
CurrentCtrName,NewCtrName);
/* Change current centre name in order to display it properly */
- Str_Copy (CurrentCtrName,NewCtrName,
- MaxBytes);
+ Str_Copy (CurrentCtrName,NewCtrName,MaxBytes);
}
}
else // The same name
@@ -1485,8 +1478,7 @@ void Ctr_ChangeCtrWWW (void)
{
/***** Update database changing old WWW by new WWW *****/
Ctr_UpdateCtrWWWDB (Ctr_EditingCtr->CtrCod,NewWWW);
- Str_Copy (Ctr_EditingCtr->WWW,NewWWW,
- Cns_MAX_BYTES_WWW);
+ Str_Copy (Ctr_EditingCtr->WWW,NewWWW,sizeof (Ctr_EditingCtr->WWW) - 1);
/***** Write message to show the change made
and put button to go to centre changed *****/
@@ -2279,8 +2271,8 @@ static void Ctr_EditingCentreConstructor (void)
Lay_ShowErrorAndExit ("Error initializing centre.");
/***** Allocate memory for centre *****/
- if ((Ctr_EditingCtr = (struct Ctr_Centre *) malloc (sizeof (struct Ctr_Centre))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for centre.");
+ if ((Ctr_EditingCtr = malloc (sizeof (*Ctr_EditingCtr))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/***** Reset centre *****/
Ctr_EditingCtr->CtrCod = -1L;
diff --git a/swad_centre_config.c b/swad_centre_config.c
index 37c1727c..0d03db10 100644
--- a/swad_centre_config.c
+++ b/swad_centre_config.c
@@ -228,12 +228,11 @@ static void CtrCfg_Configuration (bool PrintView)
MapIsAvailable = Ctr_GetIfMapIsAvailable (&Gbl.Hierarchy.Ctr);
/***** Check photo *****/
- snprintf (PathPhoto,sizeof (PathPhoto),
- "%s/%02u/%u/%u.jpg",
+ snprintf (PathPhoto,sizeof (PathPhoto),"%s/%02u/%u/%u.jpg",
Cfg_PATH_CTR_PUBLIC,
(unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100),
- (unsigned) Gbl.Hierarchy.Ctr.CtrCod,
- (unsigned) Gbl.Hierarchy.Ctr.CtrCod);
+ (unsigned) Gbl.Hierarchy.Ctr.CtrCod,
+ (unsigned) Gbl.Hierarchy.Ctr.CtrCod);
PhotoExists = Fil_CheckIfPathExists (PathPhoto);
if (MapIsAvailable || PhotoExists)
@@ -292,8 +291,7 @@ static void CtrCfg_PutIconToChangePhoto (void)
bool PhotoExists;
/***** Link to upload photo of centre *****/
- snprintf (PathPhoto,sizeof (PathPhoto),
- "%s/%02u/%u/%u.jpg",
+ snprintf (PathPhoto,sizeof (PathPhoto),"%s/%02u/%u/%u.jpg",
Cfg_PATH_CTR_PUBLIC,
(unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100),
(unsigned) Gbl.Hierarchy.Ctr.CtrCod,
@@ -531,10 +529,9 @@ static void CtrCfg_GetPhotoAttr (long CtrCod,char **PhotoAttribution)
if (row[0][0])
{
Length = strlen (row[0]);
- if (((*PhotoAttribution) = (char *) malloc (Length + 1)) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for photo attribution.");
- Str_Copy (*PhotoAttribution,row[0],
- Length);
+ if (((*PhotoAttribution) = malloc (Length + 1)) == NULL)
+ Lay_NotEnoughMemoryExit ();
+ Str_Copy (*PhotoAttribution,row[0],Length);
}
}
@@ -936,8 +933,7 @@ void CtrCfg_ReceivePhoto (void)
}
/* End the reception of image in a temporary file */
- snprintf (PathFileImgTmp,sizeof (PathFileImgTmp),
- "%s/%s.%s",
+ snprintf (PathFileImgTmp,sizeof (PathFileImgTmp),"%s/%s.%s",
Cfg_PATH_MEDIA_TMP_PRIVATE,Gbl.UniqueNameEncrypted,PtrExtension);
if (!Fil_EndReceptionOfFile (PathFileImgTmp,Param))
{
@@ -947,29 +943,25 @@ void CtrCfg_ReceivePhoto (void)
/***** Creates public directories if not exist *****/
Fil_CreateDirIfNotExists (Cfg_PATH_CTR_PUBLIC);
- snprintf (Path,sizeof (Path),
- "%s/%02u",
- Cfg_PATH_CTR_PUBLIC,
- (unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100));
+ snprintf (Path,sizeof (Path),"%s/%02u",
+ Cfg_PATH_CTR_PUBLIC,(unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100));
Fil_CreateDirIfNotExists (Path);
- snprintf (Path,sizeof (Path),
- "%s/%02u/%u",
+ snprintf (Path,sizeof (Path),"%s/%02u/%u",
Cfg_PATH_CTR_PUBLIC,
(unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100),
- (unsigned) Gbl.Hierarchy.Ctr.CtrCod);
+ (unsigned) Gbl.Hierarchy.Ctr.CtrCod);
Fil_CreateDirIfNotExists (Path);
/***** Convert temporary file to public JPEG file *****/
- snprintf (PathFileImg,sizeof (PathFileImg),
- "%s/%02u/%u/%u.jpg",
+ snprintf (PathFileImg,sizeof (PathFileImg),"%s/%02u/%u/%u.jpg",
Cfg_PATH_CTR_PUBLIC,
(unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100),
- (unsigned) Gbl.Hierarchy.Ctr.CtrCod,
- (unsigned) Gbl.Hierarchy.Ctr.CtrCod);
+ (unsigned) Gbl.Hierarchy.Ctr.CtrCod,
+ (unsigned) Gbl.Hierarchy.Ctr.CtrCod);
/* Call to program that makes the conversion */
snprintf (Command,sizeof (Command),
- "convert %s -resize '%ux%u>' -quality %u %s",
+ "convert %s -resize '%ux%u>' -quality %u %s",
PathFileImgTmp,
Ctr_PHOTO_SAVED_MAX_WIDTH,
Ctr_PHOTO_SAVED_MAX_HEIGHT,
@@ -1220,7 +1212,7 @@ void CtrCfg_ChangeCtrWWW (void)
/***** Update database changing old WWW by new WWW *****/
Ctr_UpdateCtrWWWDB (Gbl.Hierarchy.Ctr.CtrCod,NewWWW);
Str_Copy (Gbl.Hierarchy.Ctr.WWW,NewWWW,
- Cns_MAX_BYTES_WWW);
+ sizeof (Gbl.Hierarchy.Ctr.WWW) - 1);
/***** Write message to show the change made *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_The_new_web_address_is_X,
diff --git a/swad_changelog.h b/swad_changelog.h
index 841ef611..16e5e2df 100644
--- a/swad_changelog.h
+++ b/swad_changelog.h
@@ -553,7 +553,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
En OpenSWAD:
ps2pdf source.ps destination.pdf
*/
-#define Log_PLATFORM_VERSION "SWAD 20.30.1 (2021-02-14)"
+#define Log_PLATFORM_VERSION "SWAD 20.31 (2021-02-15)"
#define CSS_FILE "swad20.8.css"
#define JS_FILE "swad20.6.2.js"
/*
@@ -601,6 +601,7 @@ TODO: DNI de un estudiante sale err
TODO: BUG: Cuando un tipo de grupo sólo tiene un grupo, inscribirse es voluntario, el estudiante sólo puede pertenecer a un grupo, y se inscribe en él, debería poder desapuntarse. Ahora no puede.
TODO: Salvador Romero Cortés: @acanas opción para editar posts
+ Version 20.31: Feb 15, 2021 Code refactoring in copy, concat and sprintf. (304811 lines)
Version 20.30.1: Feb 14, 2021 Code refactoring in timeline related to temporary tables. (305883 lines)
Version 20.30: Feb 11, 2021 Code refactoring in hierarchy. (305853 lines)
Version 20.29.3: Feb 11, 2021 Code refactoring in timeline. (305826 lines)
diff --git a/swad_chat.c b/swad_chat.c
index 1be41f9b..6cd54a57 100644
--- a/swad_chat.c
+++ b/swad_chat.c
@@ -138,8 +138,7 @@ void Cht_ShowListOfAvailableChatRooms (void)
/***** Link to chat available for all the users *****/
IsLastItemInLevel[1] = (!Gbl.Usrs.Me.IBelongToCurrentCrs &&
!Gbl.Usrs.Me.MyDegs.Num);
- snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),
- "%s (%s)",
+ snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s (%s)",
Txt_General,Txt_SEX_PLURAL_abc[Usr_SEX_ALL]);
Cht_WriteLinkToChat1 ("GBL_USR",Txt_SEX_PLURAL_Abc[Usr_SEX_ALL],ThisRoomFullName,1,IsLastItemInLevel);
Ico_PutIcon ("comments.svg",ThisRoomFullName,"ICO16x16");
@@ -149,19 +148,19 @@ void Cht_ShowListOfAvailableChatRooms (void)
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_STD:
- snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),
- "%s (%s)",
+ snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s (%s)",
Txt_General,Txt_ROLES_PLURAL_abc[Rol_STD][Usr_SEX_ALL]);
- Cht_WriteLinkToChat1 ("GBL_STD",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD],ThisRoomFullName,1,IsLastItemInLevel);
+ Cht_WriteLinkToChat1 ("GBL_STD",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD],
+ ThisRoomFullName,1,IsLastItemInLevel);
Ico_PutIcon ("comments.svg",ThisRoomFullName,"ICO16x16");
Cht_WriteLinkToChat2 ("GBL_STD",ThisRoomFullName);
break;
case Rol_NET:
case Rol_TCH:
- snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),
- "%s (%s)",
+ snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s (%s)",
Txt_General,Txt_ROLES_PLURAL_abc[Rol_TCH][Usr_SEX_ALL]);
- Cht_WriteLinkToChat1 ("GBL_TCH",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH],ThisRoomFullName,1,IsLastItemInLevel);
+ Cht_WriteLinkToChat1 ("GBL_TCH",Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH],
+ ThisRoomFullName,1,IsLastItemInLevel);
Ico_PutIcon ("comments.svg",ThisRoomFullName,"ICO16x16");
Cht_WriteLinkToChat2 ("GBL_TCH",ThisRoomFullName);
break;
@@ -181,14 +180,10 @@ void Cht_ShowListOfAvailableChatRooms (void)
/* Link to the room of this degree */
IsLastItemInLevel[1] = (NumMyDeg == Gbl.Usrs.Me.MyDegs.Num - 1);
- snprintf (ThisRoomCode,sizeof (ThisRoomCode),
- "DEG_%ld",
- Deg.DegCod);
- snprintf (ThisRoomShrtName,sizeof (ThisRoomShrtName),
- "%s",
+ snprintf (ThisRoomCode,sizeof (ThisRoomCode),"DEG_%ld",Deg.DegCod);
+ snprintf (ThisRoomShrtName,sizeof (ThisRoomShrtName),"%s",
Deg.ShrtName);
- snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),
- "%s %s",
+ snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s %s",
Txt_Degree,Deg.ShrtName);
Cht_WriteLinkToChat1 (ThisRoomCode,ThisRoomShrtName,ThisRoomFullName,1,IsLastItemInLevel);
Lgo_DrawLogo (Hie_Lvl_DEG,Deg.DegCod,Deg.ShrtName,16,NULL,true);
@@ -211,14 +206,11 @@ void Cht_ShowListOfAvailableChatRooms (void)
/* Link to the room of this course */
IsLastItemInLevel[2] = (NumRow == NumRows - 1);
- snprintf (ThisRoomCode,sizeof (ThisRoomCode),
- "CRS_%ld",
+ snprintf (ThisRoomCode,sizeof (ThisRoomCode),"CRS_%ld",
Crs.CrsCod);
- snprintf (ThisRoomShrtName,sizeof (ThisRoomShrtName),
- "%s",
+ snprintf (ThisRoomShrtName,sizeof (ThisRoomShrtName),"%s",
Crs.ShrtName);
- snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),
- "%s %s",
+ snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s %s",
Txt_Course,Crs.ShrtName);
Cht_WriteLinkToChat1 (ThisRoomCode,ThisRoomShrtName,ThisRoomFullName,2,IsLastItemInLevel);
Ico_PutIcon ("chalkboard-teacher.svg",ThisRoomFullName,"ICO16x16");
@@ -427,119 +419,86 @@ void Cht_OpenChatWindow (void)
Usr_GetMyCourses ();
/***** Build my user's name *****/
- Str_Copy (UsrName,Gbl.Usrs.Me.UsrDat.Surname1,
- Usr_MAX_BYTES_FULL_NAME);
+ Str_Copy (UsrName,Gbl.Usrs.Me.UsrDat.Surname1,sizeof (UsrName) - 1);
if (Gbl.Usrs.Me.UsrDat.Surname2[0])
{
- Str_Concat (UsrName," ",
- Usr_MAX_BYTES_FULL_NAME);
- Str_Concat (UsrName,Gbl.Usrs.Me.UsrDat.Surname2,
- Usr_MAX_BYTES_FULL_NAME);
+ Str_Concat (UsrName," ",sizeof (UsrName) - 1);
+ Str_Concat (UsrName,Gbl.Usrs.Me.UsrDat.Surname2,sizeof (UsrName) - 1);
}
- Str_Concat (UsrName,", ",
- Usr_MAX_BYTES_FULL_NAME);
- Str_Concat (UsrName,Gbl.Usrs.Me.UsrDat.FirstName,
- Usr_MAX_BYTES_FULL_NAME);
+ Str_Concat (UsrName,", ",sizeof (UsrName) - 1);
+ Str_Concat (UsrName,Gbl.Usrs.Me.UsrDat.FrstName,sizeof (UsrName) - 1);
/***** Build the lists of available rooms *****/
- snprintf (ListRoomCodes,sizeof (ListRoomCodes),
- "#%s",
- RoomCode);
- Str_Copy (ListRoomShrtNames,RoomShrtName,
- Cht_MAX_BYTES_ROOM_SHRT_NAMES);
- Str_Copy (ListRoomFullNames ,RoomFullName,
- Cht_MAX_BYTES_ROOM_FULL_NAMES);
+ snprintf (ListRoomCodes,sizeof (ListRoomCodes),"#%s",RoomCode);
+ Str_Copy (ListRoomShrtNames,RoomShrtName,sizeof (ListRoomShrtNames) - 1);
+ Str_Copy (ListRoomFullNames,RoomFullName,sizeof (ListRoomFullNames) - 1);
if (strcmp (RoomCode,"GBL_USR"))
{
- Str_Concat (ListRoomCodes,"|#GBL_USR",
- Cht_MAX_BYTES_ROOM_CODES);
+ Str_Concat (ListRoomCodes,"|#GBL_USR",sizeof (ListRoomCodes) - 1);
- snprintf (RoomShrtName,sizeof (RoomShrtName),
- "|%s",
+ snprintf (RoomShrtName,sizeof (RoomShrtName),"|%s",
Txt_SEX_PLURAL_Abc[Usr_SEX_ALL]);
- Str_Concat (ListRoomShrtNames,RoomShrtName,
- Cht_MAX_BYTES_ROOM_SHRT_NAMES);
+ Str_Concat (ListRoomShrtNames,RoomShrtName,sizeof (ListRoomShrtNames) - 1);
- snprintf (RoomFullName,sizeof (RoomFullName),
- "|%s (%s)",
+ snprintf (RoomFullName,sizeof (RoomFullName),"|%s (%s)",
Txt_General,Txt_SEX_PLURAL_abc[Usr_SEX_ALL]);
- Str_Concat (ListRoomFullNames,RoomFullName,
- Cht_MAX_BYTES_ROOM_FULL_NAMES);
+ Str_Concat (ListRoomFullNames,RoomFullName,sizeof (ListRoomFullNames) - 1);
}
if (Gbl.Usrs.Me.Role.Logged == Rol_STD)
if (strcmp (RoomCode,"GBL_STD"))
{
- Str_Concat (ListRoomCodes,"|#GBL_STD",
- Cht_MAX_BYTES_ROOM_CODES);
+ Str_Concat (ListRoomCodes,"|#GBL_STD",sizeof (ListRoomCodes) - 1);
- snprintf (RoomShrtName,sizeof (RoomShrtName),
- "|%s",
+ snprintf (RoomShrtName,sizeof (RoomShrtName),"|%s",
Txt_ROLES_PLURAL_BRIEF_Abc[Rol_STD]);
- Str_Concat (ListRoomShrtNames,RoomShrtName,
- Cht_MAX_BYTES_ROOM_SHRT_NAMES);
+ Str_Concat (ListRoomShrtNames,RoomShrtName,sizeof (ListRoomShrtNames) - 1);
- snprintf (RoomFullName,sizeof (RoomFullName),
- "|%s (%s)",
+ snprintf (RoomFullName,sizeof (RoomFullName),"|%s (%s)",
Txt_General,Txt_ROLES_PLURAL_abc[Rol_STD][Usr_SEX_ALL]);
- Str_Concat (ListRoomFullNames,RoomFullName,
- Cht_MAX_BYTES_ROOM_FULL_NAMES);
+ Str_Concat (ListRoomFullNames,RoomFullName,sizeof (ListRoomFullNames) - 1);
}
if (Gbl.Usrs.Me.Role.Logged == Rol_NET ||
Gbl.Usrs.Me.Role.Logged == Rol_TCH)
if (strcmp (RoomCode,"GBL_TCH"))
{
- Str_Concat (ListRoomCodes,"|#GBL_TCH",
- Cht_MAX_BYTES_ROOM_CODES);
+ Str_Concat (ListRoomCodes,"|#GBL_TCH",sizeof (ListRoomCodes) - 1);
- snprintf (RoomShrtName,sizeof (RoomShrtName),
- "|%s",
+ snprintf (RoomShrtName,sizeof (RoomShrtName),"|%s",
Txt_ROLES_PLURAL_BRIEF_Abc[Rol_TCH]);
- Str_Concat (ListRoomShrtNames,RoomShrtName,
- Cht_MAX_BYTES_ROOM_SHRT_NAMES);
+ Str_Concat (ListRoomShrtNames,RoomShrtName,sizeof (ListRoomShrtNames) - 1);
- snprintf (RoomFullName,sizeof (RoomFullName),
- "|%s (%s)",
+ snprintf (RoomFullName,sizeof (RoomFullName),"|%s (%s)",
Txt_General,Txt_ROLES_PLURAL_abc[Rol_TCH][Usr_SEX_ALL]);
- Str_Concat (ListRoomFullNames,RoomFullName,
- Cht_MAX_BYTES_ROOM_FULL_NAMES);
+ Str_Concat (ListRoomFullNames,RoomFullName,sizeof (ListRoomFullNames) - 1);
}
for (NumMyDeg = 0;
NumMyDeg < Gbl.Usrs.Me.MyDegs.Num;
NumMyDeg++)
{
- snprintf (ThisRoomCode,sizeof (ThisRoomCode),
- "DEG_%ld",
+ snprintf (ThisRoomCode,sizeof (ThisRoomCode),"DEG_%ld",
Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod);
if (strcmp (RoomCode,ThisRoomCode))
{
- Str_Concat (ListRoomCodes,"|#",
- Cht_MAX_BYTES_ROOM_CODES);
- Str_Concat (ListRoomCodes,ThisRoomCode,
- Cht_MAX_BYTES_ROOM_CODES);
+ Str_Concat (ListRoomCodes,"|#",sizeof (ListRoomCodes) - 1);
+ Str_Concat (ListRoomCodes,ThisRoomCode,sizeof (ListRoomCodes) - 1);
/* Get data of this degree */
Deg.DegCod = Gbl.Usrs.Me.MyDegs.Degs[NumMyDeg].DegCod;
Deg_GetDataOfDegreeByCod (&Deg);
- snprintf (ThisRoomShortName,sizeof (ThisRoomShortName),
- "%s",
+ snprintf (ThisRoomShortName,sizeof (ThisRoomShortName),"%s",
Deg.ShrtName);
- Str_Concat (ListRoomShrtNames,"|",
- Cht_MAX_BYTES_ROOM_SHRT_NAMES);
- Str_Concat (ListRoomShrtNames,ThisRoomShortName,
- Cht_MAX_BYTES_ROOM_SHRT_NAMES);
+ Str_Concat (ListRoomShrtNames,"|",sizeof (ListRoomShrtNames) - 1);
+ Str_Concat (ListRoomShrtNames,ThisRoomShortName,sizeof (ListRoomShrtNames) - 1);
- snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),
- "%s %s",
+ snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s %s",
Txt_Degree,Deg.ShrtName);
- Str_Concat (ListRoomFullNames,"|",
- Cht_MAX_BYTES_ROOM_FULL_NAMES);
- Str_Concat (ListRoomFullNames,ThisRoomFullName,
- Cht_MAX_BYTES_ROOM_FULL_NAMES);
+ Str_Concat (ListRoomFullNames,"|",sizeof (ListRoomFullNames) - 1);
+ Str_Concat (ListRoomFullNames,ThisRoomFullName,sizeof (ListRoomFullNames) - 1);
}
}
@@ -547,15 +506,12 @@ void Cht_OpenChatWindow (void)
NumMyCrs < Gbl.Usrs.Me.MyCrss.Num;
NumMyCrs++)
{
- snprintf (ThisRoomCode,sizeof (ThisRoomCode),
- "CRS_%ld",
+ snprintf (ThisRoomCode,sizeof (ThisRoomCode),"CRS_%ld",
Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod);
if (strcmp (RoomCode,ThisRoomCode))
{
- Str_Concat (ListRoomCodes,"|#",
- Cht_MAX_BYTES_ROOM_CODES);
- Str_Concat (ListRoomCodes,ThisRoomCode,
- Cht_MAX_BYTES_ROOM_CODES);
+ Str_Concat (ListRoomCodes,"|#",sizeof (ListRoomCodes) - 1);
+ Str_Concat (ListRoomCodes,ThisRoomCode,sizeof (ListRoomCodes) - 1);
/* Get data of this course */
Crs.CrsCod = Gbl.Usrs.Me.MyCrss.Crss[NumMyCrs].CrsCod;
@@ -564,18 +520,13 @@ void Cht_OpenChatWindow (void)
snprintf (ThisRoomShortName,sizeof (ThisRoomShortName),
"%s",
Crs.ShrtName);
- Str_Concat (ListRoomShrtNames,"|",
- Cht_MAX_BYTES_ROOM_SHRT_NAMES);
- Str_Concat (ListRoomShrtNames,ThisRoomShortName,
- Cht_MAX_BYTES_ROOM_SHRT_NAMES);
+ Str_Concat (ListRoomShrtNames,"|",sizeof (ListRoomShrtNames) - 1);
+ Str_Concat (ListRoomShrtNames,ThisRoomShortName,sizeof (ListRoomShrtNames) - 1);
- snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),
- "%s %s",
+ snprintf (ThisRoomFullName,sizeof (ThisRoomFullName),"%s %s",
Txt_Course,Crs.ShrtName);
- Str_Concat (ListRoomFullNames,"|",
- Cht_MAX_BYTES_ROOM_FULL_NAMES);
- Str_Concat (ListRoomFullNames,ThisRoomFullName,
- Cht_MAX_BYTES_ROOM_FULL_NAMES);
+ Str_Concat (ListRoomFullNames,"|",sizeof (ListRoomFullNames) - 1);
+ Str_Concat (ListRoomFullNames,ThisRoomFullName,sizeof (ListRoomFullNames) - 1);
}
}
diff --git a/swad_config.c b/swad_config.c
index 948583a1..b5efecff 100644
--- a/swad_config.c
+++ b/swad_config.c
@@ -86,7 +86,7 @@ void Cfg_GetConfigFromFile (void)
fseek (FileCfg,0L,SEEK_SET);
/* Allocate memory for buffer */
- if ((Config = (char *) malloc (Length + 1)) == NULL)
+ if ((Config = malloc (Length + 1)) == NULL)
{
fclose (FileCfg);
Lay_NotEnoughMemoryExit ();
diff --git a/swad_connected.c b/swad_connected.c
index 5b50ecdb..c0a1eb7b 100644
--- a/swad_connected.c
+++ b/swad_connected.c
@@ -321,8 +321,7 @@ void Con_ShowConnectedUsrsBelongingToCurrentCrs (void)
// the list of connected users
// is dynamically updated via AJAX
HTM_BUTTON_SUBMIT_Begin (Txt_Connected_users,"BT_LINK CONNECTED_TXT",NULL);
- Str_Copy (CourseName,Gbl.Hierarchy.Crs.ShrtName,
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ Str_Copy (CourseName,Gbl.Hierarchy.Crs.ShrtName,sizeof (CourseName) - 1);
Con_GetNumConnectedUsrsWithARoleBelongingCurrentLocation (Rol_UNK,&Usrs);
HTM_TxtF ("%u %s %s",Usrs.NumUsrs,Txt_from,CourseName);
HTM_BUTTON_End ();
@@ -851,7 +850,7 @@ static void Con_WriteRowConnectedUsrOnRightColumn (Rol_Role_t Role)
Rol_WrongRoleExit ();
break;
}
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_DIV_Begin ("class=\"CON_NAME_NARROW\""); // Limited width
HTM_BUTTON_SUBMIT_Begin (Txt_View_record_for_this_course,ClassLink,NULL);
@@ -1075,7 +1074,7 @@ static void Con_ShowConnectedUsrsCurrentLocationOneByOneOnMainZone (Rol_Role_t R
default:
Rol_WrongRoleExit ();
}
- Usr_PutParamUsrCodEncrypted (UsrDat.EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat.EnUsrCod);
}
HTM_DIV_Begin ("class=\"CON_NAME_WIDE\""); // Limited width
diff --git a/swad_country.c b/swad_country.c
index b76965e7..71a11388 100644
--- a/swad_country.c
+++ b/swad_country.c
@@ -533,7 +533,7 @@ void Cty_DrawCountryMapAndNameWithLink (struct Cty_Countr *Cty,Act_Action_t Acti
/***** Write country name *****/
Str_Copy (CountryName,Cty->Name[Gbl.Prefs.Language],
- Cty_MAX_BYTES_NAME);
+ sizeof (CountryName) - 1);
HTM_TxtF (" %s ",CountryName);
HTM_TxtF ("(%s)",Cty->Alpha2);
@@ -581,8 +581,7 @@ bool Cty_CheckIfCountryPhotoExists (struct Cty_Countr *Cty)
{
char PathMap[PATH_MAX + 1];
- snprintf (PathMap,sizeof (PathMap),
- "%s/%s/%s.png",
+ snprintf (PathMap,sizeof (PathMap),"%s/%s/%s.png",
Cfg_PATH_ICON_COUNTRIES_PUBLIC,
Cty->Alpha2,
Cty->Alpha2);
@@ -768,8 +767,8 @@ void Cty_GetBasicListOfCountries (void)
Gbl.Hierarchy.Ctys.Num = (unsigned) NumRows;
/***** Create list with countries *****/
- if ((Gbl.Hierarchy.Ctys.Lst = (struct Cty_Countr *)
- calloc (NumRows,sizeof (struct Cty_Countr))) == NULL)
+ if ((Gbl.Hierarchy.Ctys.Lst = calloc (NumRows,
+ sizeof (*Gbl.Hierarchy.Ctys.Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the countries *****/
@@ -787,8 +786,7 @@ void Cty_GetBasicListOfCountries (void)
Lay_ShowErrorAndExit ("Wrong code of country.");
/* Get Alpha-2 country code (row[1]) */
- Str_Copy (Cty->Alpha2,row[1],
- 2);
+ Str_Copy (Cty->Alpha2,row[1],sizeof (Cty->Alpha2) - 1);
for (Lan = (Lan_Language_t) 1;
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
@@ -800,7 +798,7 @@ void Cty_GetBasicListOfCountries (void)
/* Get the name of the country in current language */
Str_Copy (Cty->Name[Gbl.Prefs.Language],row[2],
- Cty_MAX_BYTES_NAME);
+ sizeof (Cty->Name[Gbl.Prefs.Language]) - 1);
/* Reset number of users who claim to belong to country */
Cty->NumUsrsWhoClaimToBelongToCty.Valid = false;
@@ -850,27 +848,15 @@ void Cty_GetFullListOfCountries (void)
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
Lan++)
{
- snprintf (StrField,sizeof (StrField),
- "countries.Name_%s,",
- Lan_STR_LANG_ID[Lan]);
- Str_Concat (SubQueryNam1,StrField,
- Cty_MAX_BYTES_SUBQUERY_CTYS);
- snprintf (StrField,sizeof (StrField),
- "Name_%s,",
- Lan_STR_LANG_ID[Lan]);
- Str_Concat (SubQueryNam2,StrField,
- Cty_MAX_BYTES_SUBQUERY_CTYS);
+ snprintf (StrField,sizeof (StrField),"countries.Name_%s,",Lan_STR_LANG_ID[Lan]);
+ Str_Concat (SubQueryNam1,StrField,sizeof (SubQueryNam1) - 1);
+ snprintf (StrField,sizeof (StrField),"Name_%s,",Lan_STR_LANG_ID[Lan]);
+ Str_Concat (SubQueryNam2,StrField,sizeof (SubQueryNam2) - 1);
- snprintf (StrField,sizeof (StrField),
- "countries.WWW_%s,",
- Lan_STR_LANG_ID[Lan]);
- Str_Concat (SubQueryWWW1,StrField,
- Cty_MAX_BYTES_SUBQUERY_CTYS);
- snprintf (StrField,sizeof (StrField),
- "WWW_%s,",
- Lan_STR_LANG_ID[Lan]);
- Str_Concat (SubQueryWWW2,StrField,
- Cty_MAX_BYTES_SUBQUERY_CTYS);
+ snprintf (StrField,sizeof (StrField),"countries.WWW_%s,",Lan_STR_LANG_ID[Lan]);
+ Str_Concat (SubQueryWWW1,StrField,sizeof (SubQueryWWW1) - 1);
+ snprintf (StrField,sizeof (StrField),"WWW_%s,",Lan_STR_LANG_ID[Lan]);
+ Str_Concat (SubQueryWWW2,StrField,sizeof (SubQueryWWW2) - 1);
}
/* Build order subquery */
@@ -902,8 +888,8 @@ void Cty_GetFullListOfCountries (void)
Gbl.Hierarchy.Ctys.Num = (unsigned) NumRows;
/***** Create list with countries *****/
- if ((Gbl.Hierarchy.Ctys.Lst = (struct Cty_Countr *)
- calloc (NumRows,sizeof (struct Cty_Countr))) == NULL)
+ if ((Gbl.Hierarchy.Ctys.Lst = calloc (NumRows,
+ sizeof (*Gbl.Hierarchy.Ctys.Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the countries *****/
@@ -921,8 +907,7 @@ void Cty_GetFullListOfCountries (void)
Lay_ShowErrorAndExit ("Wrong code of country.");
/* Get Alpha-2 country code (row[1]) */
- Str_Copy (Cty->Alpha2,row[1],
- 2);
+ Str_Copy (Cty->Alpha2,row[1],sizeof (Cty->Alpha2) - 1);
/* Get the name of the country in several languages */
for (Lan = (Lan_Language_t) 1;
@@ -930,9 +915,9 @@ void Cty_GetFullListOfCountries (void)
Lan++)
{
Str_Copy (Cty->Name[Lan],row[1 + Lan],
- Cty_MAX_BYTES_NAME);
+ sizeof (Cty->Name[Lan]) - 1);
Str_Copy (Cty->WWW[Lan],row[1 + Lan_NUM_LANGUAGES + Lan],
- Cns_MAX_BYTES_WWW);
+ sizeof (Cty->WWW[Lan]) - 1);
}
/* Get number of users who claim to belong to this country */
@@ -1069,7 +1054,7 @@ bool Cty_GetDataOfCountryByCod (struct Cty_Countr *Cty)
Lan++)
if (Lan == Gbl.Prefs.Language)
Str_Copy (Cty->Name[Lan],Txt_Another_country,
- Cty_MAX_BYTES_NAME);
+ sizeof (Cty->Name[Lan]) - 1);
else
Cty->Name[Lan][0] = '\0';
return false;
@@ -1095,14 +1080,13 @@ bool Cty_GetDataOfCountryByCod (struct Cty_Countr *Cty)
row = mysql_fetch_row (mysql_res);
/* Get Alpha-2 country code (row[0]) */
- Str_Copy (Cty->Alpha2,row[0],
- 2);
+ Str_Copy (Cty->Alpha2,row[0],sizeof (Cty->Alpha2) - 1);
/* Get name and WWW of the country in current language */
Str_Copy (Cty->Name[Gbl.Prefs.Language],row[1],
- Cty_MAX_BYTES_NAME);
+ sizeof (Cty->Name[Gbl.Prefs.Language]) - 1);
Str_Copy (Cty->WWW[Gbl.Prefs.Language],row[2],
- Cns_MAX_BYTES_WWW);
+ sizeof (Cty->WWW[Gbl.Prefs.Language]) - 1);
}
else
CtyFound = false;
@@ -1142,8 +1126,7 @@ void Cty_GetCountryName (long CtyCod,Lan_Language_t Language,
if (CtyCod == Gbl.Cache.CountryName.CtyCod &&
Language == Gbl.Cache.CountryName.Language)
{
- Str_Copy (CtyName,Gbl.Cache.CountryName.CtyName,
- Cty_MAX_BYTES_NAME);
+ Str_Copy (CtyName,Gbl.Cache.CountryName.CtyName,Cty_MAX_BYTES_NAME);
return;
}
@@ -1160,7 +1143,7 @@ void Cty_GetCountryName (long CtyCod,Lan_Language_t Language,
/* Get the name of the country */
Str_Copy (Gbl.Cache.CountryName.CtyName,row[0],
- Cty_MAX_BYTES_NAME);
+ sizeof (Gbl.Cache.CountryName.CtyName) - 1);
}
else
Gbl.Cache.CountryName.CtyName[0] = '\0';
@@ -1168,8 +1151,7 @@ void Cty_GetCountryName (long CtyCod,Lan_Language_t Language,
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
- Str_Copy (CtyName,Gbl.Cache.CountryName.CtyName,
- Cty_MAX_BYTES_NAME);
+ Str_Copy (CtyName,Gbl.Cache.CountryName.CtyName,Cty_MAX_BYTES_NAME);
}
/*****************************************************************************/
@@ -1441,8 +1423,7 @@ void Cty_RenameCountry (void)
else
{
/* Update the table changing old name by new name */
- snprintf (FieldName,sizeof (FieldName),
- "Name_%s",
+ snprintf (FieldName,sizeof (FieldName),"Name_%s",
Lan_STR_LANG_ID[Language]);
Cty_UpdateCtyNameDB (Cty_EditingCty->CtyCod,FieldName,NewCtyName);
@@ -1453,7 +1434,7 @@ void Cty_RenameCountry (void)
/* Update country name */
Str_Copy (Cty_EditingCty->Name[Language],NewCtyName,
- Cty_MAX_BYTES_NAME);
+ sizeof (Cty_EditingCty->Name[Language]) - 1);
}
}
else // The same name
@@ -1556,7 +1537,7 @@ void Cty_ChangeCtyWWW (void)
" WHERE CtyCod='%03ld'",
Lan_STR_LANG_ID[Language],NewWWW,Cty_EditingCty->CtyCod);
Str_Copy (Cty_EditingCty->WWW[Language],NewWWW,
- Cns_MAX_BYTES_WWW);
+ sizeof (Cty_EditingCty->WWW[Language]) - 1);
/***** Write message to show the change made *****/
Ale_CreateAlert (Ale_SUCCESS,NULL,
@@ -1644,9 +1625,7 @@ static void Cty_PutFormToCreateCountry (void)
/***** Numerical country code (ISO 3166-1) *****/
HTM_TD_Begin ("rowspan=\"%u\" class=\"RT\"",1 + Lan_NUM_LANGUAGES);
if (Cty_EditingCty->CtyCod > 0)
- snprintf (StrCtyCod,sizeof (StrCtyCod),
- "%03ld",
- Cty_EditingCty->CtyCod);
+ snprintf (StrCtyCod,sizeof (StrCtyCod),"%03ld",Cty_EditingCty->CtyCod);
else
StrCtyCod[0] = '\0';
HTM_INPUT_TEXT ("OthCtyCod",3,StrCtyCod,HTM_DONT_SUBMIT_ON_CHANGE,
@@ -1687,9 +1666,7 @@ static void Cty_PutFormToCreateCountry (void)
/* Name */
HTM_TD_Begin ("class=\"LM\"");
- snprintf (StrName,sizeof (StrName),
- "Name_%s",
- Lan_STR_LANG_ID[Lan]);
+ snprintf (StrName,sizeof (StrName),"Name_%s",Lan_STR_LANG_ID[Lan]);
HTM_INPUT_TEXT (StrName,Cty_MAX_CHARS_NAME,Cty_EditingCty->Name[Lan],
HTM_DONT_SUBMIT_ON_CHANGE,
"size=\"15\" required=\"required\"");
@@ -1697,9 +1674,7 @@ static void Cty_PutFormToCreateCountry (void)
/* WWW */
HTM_TD_Begin ("class=\"LM\"");
- snprintf (StrName,sizeof (StrName),
- "WWW_%s",
- Lan_STR_LANG_ID[Lan]);
+ snprintf (StrName,sizeof (StrName),"WWW_%s",Lan_STR_LANG_ID[Lan]);
HTM_INPUT_URL (StrName,Cty_EditingCty->WWW[Lan],HTM_DONT_SUBMIT_ON_CHANGE,
"class=\"INPUT_WWW_NARROW\" required=\"required\"");
HTM_TD_End ();
@@ -1810,9 +1785,7 @@ void Cty_ReceiveFormNewCountry (void)
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
Lan++)
{
- snprintf (ParamName,sizeof (ParamName),
- "Name_%s",
- Lan_STR_LANG_ID[Lan]);
+ snprintf (ParamName,sizeof (ParamName),"Name_%s",Lan_STR_LANG_ID[Lan]);
Par_GetParToText (ParamName,Cty_EditingCty->Name[Lan],Cty_MAX_BYTES_NAME);
if (Cty_EditingCty->Name[Lan][0]) // If there's a country name
@@ -1835,9 +1808,7 @@ void Cty_ReceiveFormNewCountry (void)
break;
}
- snprintf (ParamName,sizeof (ParamName),
- "WWW_%s",
- Lan_STR_LANG_ID[Lan]);
+ snprintf (ParamName,sizeof (ParamName),"WWW_%s",Lan_STR_LANG_ID[Lan]);
Par_GetParToText (ParamName,Cty_EditingCty->WWW[Lan],Cns_MAX_BYTES_WWW);
}
}
@@ -1878,31 +1849,19 @@ static void Cty_CreateCountry (void)
Lan <= (Lan_Language_t) Lan_NUM_LANGUAGES;
Lan++)
{
- snprintf (StrField,sizeof (StrField),
- ",Name_%s",
- Lan_STR_LANG_ID[Lan]);
- Str_Concat (SubQueryNam1,StrField,
- Cty_MAX_BYTES_SUBQUERY_CTYS);
+ snprintf (StrField,sizeof (StrField),",Name_%s",Lan_STR_LANG_ID[Lan]);
+ Str_Concat (SubQueryNam1,StrField,sizeof (SubQueryNam1) - 1);
- Str_Concat (SubQueryNam2,",'",
- Cty_MAX_BYTES_SUBQUERY_CTYS_NAME);
- Str_Concat (SubQueryNam2,Cty_EditingCty->Name[Lan],
- Cty_MAX_BYTES_SUBQUERY_CTYS_NAME);
- Str_Concat (SubQueryNam2,"'",
- Cty_MAX_BYTES_SUBQUERY_CTYS_NAME);
+ Str_Concat (SubQueryNam2,",'",sizeof (SubQueryNam2) - 1);
+ Str_Concat (SubQueryNam2,Cty_EditingCty->Name[Lan],sizeof (SubQueryNam2) - 1);
+ Str_Concat (SubQueryNam2,"'",sizeof (SubQueryNam2) - 1);
- snprintf (StrField,sizeof (StrField),
- ",WWW_%s",
- Lan_STR_LANG_ID[Lan]);
- Str_Concat (SubQueryWWW1,StrField,
- Cty_MAX_BYTES_SUBQUERY_CTYS);
+ snprintf (StrField,sizeof (StrField),",WWW_%s",Lan_STR_LANG_ID[Lan]);
+ Str_Concat (SubQueryWWW1,StrField,sizeof (SubQueryWWW1) - 1);
- Str_Concat (SubQueryWWW2,",'",
- Cty_MAX_BYTES_SUBQUERY_CTYS_WWW);
- Str_Concat (SubQueryWWW2,Cty_EditingCty->WWW[Lan],
- Cty_MAX_BYTES_SUBQUERY_CTYS_WWW);
- Str_Concat (SubQueryWWW2,"'",
- Cty_MAX_BYTES_SUBQUERY_CTYS_WWW);
+ Str_Concat (SubQueryWWW2,",'",sizeof (SubQueryWWW2) - 1);
+ Str_Concat (SubQueryWWW2,Cty_EditingCty->WWW[Lan],sizeof (SubQueryWWW2) - 1);
+ Str_Concat (SubQueryWWW2,"'",sizeof (SubQueryWWW2) - 1);
}
DB_QueryINSERT ("can not create country",
"INSERT INTO countries"
@@ -2144,8 +2103,8 @@ static void Cty_EditingCountryConstructor (void)
Lay_ShowErrorAndExit ("Error initializing country.");
/***** Allocate memory for country *****/
- if ((Cty_EditingCty = (struct Cty_Countr *) malloc (sizeof (struct Cty_Countr))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for country.");
+ if ((Cty_EditingCty = malloc (sizeof (*Cty_EditingCty))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/***** Reset country *****/
Cty_EditingCty->CtyCod = -1L;
diff --git a/swad_country_config.c b/swad_country_config.c
index bf3a8f17..fc865a81 100644
--- a/swad_country_config.c
+++ b/swad_country_config.c
@@ -592,10 +592,9 @@ static void CtyCfg_GetMapAttr (long CtyCod,char **MapAttribution)
if (row[0][0])
{
Length = strlen (row[0]);
- if ((*MapAttribution = (char *) malloc (Length + 1)) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for map attribution.");
- Str_Copy (*MapAttribution,row[0],
- Length);
+ if ((*MapAttribution = malloc (Length + 1)) == NULL)
+ Lay_NotEnoughMemoryExit ();
+ Str_Copy (*MapAttribution,row[0],Length);
}
}
diff --git a/swad_course.c b/swad_course.c
index 262ce12c..33756374 100644
--- a/swad_course.c
+++ b/swad_course.c
@@ -178,8 +178,7 @@ static void Crs_WriteListMyCoursesToSelectOne (void)
char ClassHighlight[64];
ClassNormal = The_ClassFormLinkInBox[Gbl.Prefs.Theme];
- snprintf (ClassHighlight,sizeof (ClassHighlight),
- "%s LIGHT_BLUE",
+ snprintf (ClassHighlight,sizeof (ClassHighlight),"%s LIGHT_BLUE",
The_ClassFormLinkInBoxBold[Gbl.Prefs.Theme]);
/***** Begin box *****/
@@ -775,8 +774,8 @@ static void Crs_GetListCrssInCurrentDeg (Crs_WhatCourses_t WhatCourses)
if (NumCrss) // Courses found...
{
/***** Create list with courses in degree *****/
- if ((Gbl.Hierarchy.Crss.Lst = (struct Crs_Course *) calloc ((size_t) NumCrss,
- sizeof (struct Crs_Course))) == NULL)
+ if ((Gbl.Hierarchy.Crss.Lst = calloc (NumCrss,
+ sizeof (*Gbl.Hierarchy.Ctys.Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the courses in degree *****/
@@ -1804,7 +1803,7 @@ static void Crs_GetDataOfCourseFromRow (struct Crs_Course *Crs,MYSQL_ROW row)
/***** Get institutional course code (row[3]) *****/
Str_Copy (Crs->InstitutionalCrsCod,row[3],
- Crs_MAX_BYTES_INSTITUTIONAL_CRS_COD);
+ sizeof (Crs->InstitutionalCrsCod) - 1);
/***** Get course status (row[4]) *****/
if (sscanf (row[4],"%u",&(Crs->Status)) != 1)
@@ -1814,12 +1813,10 @@ static void Crs_GetDataOfCourseFromRow (struct Crs_Course *Crs,MYSQL_ROW row)
Crs->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[5]);
/***** Get the short name of the course (row[6]) *****/
- Str_Copy (Crs->ShrtName,row[6],
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ Str_Copy (Crs->ShrtName,row[6],sizeof (Crs->ShrtName) - 1);
/***** Get the full name of the course (row[7]) *****/
- Str_Copy (Crs->FullName,row[7],
- Cns_HIERARCHY_MAX_BYTES_FULL_NAME);
+ Str_Copy (Crs->FullName,row[7],sizeof (Crs->FullName) - 1);
}
/*****************************************************************************/
@@ -1848,10 +1845,8 @@ static void Crs_GetShortNamesByCod (long CrsCod,
/***** Get the short name of this course *****/
row = mysql_fetch_row (mysql_res);
- Str_Copy (CrsShortName,row[0],
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
- Str_Copy (DegShortName,row[1],
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ Str_Copy (CrsShortName,row[0],Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ Str_Copy (DegShortName,row[1],Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
}
/***** Free structure that stores the query result *****/
@@ -2024,12 +2019,10 @@ static void Crs_EmptyCourseCompletely (long CrsCod)
CrsCod);
/***** Remove directories of the course *****/
- snprintf (PathRelCrs,sizeof (PathRelCrs),
- "%s/%ld",
+ snprintf (PathRelCrs,sizeof (PathRelCrs),"%s/%ld",
Cfg_PATH_CRS_PRIVATE,CrsCod);
Fil_RemoveTree (PathRelCrs);
- snprintf (PathRelCrs,sizeof (PathRelCrs),
- "%s/%ld",
+ snprintf (PathRelCrs,sizeof (PathRelCrs),"%s/%ld",
Cfg_PATH_CRS_PUBLIC,CrsCod);
Fil_RemoveTree (PathRelCrs);
}
@@ -2170,7 +2163,7 @@ void Crs_UpdateInstitutionalCrsCod (struct Crs_Course *Crs,const char *NewInstit
/***** Copy institutional course code *****/
Str_Copy (Crs->InstitutionalCrsCod,NewInstitutionalCrsCod,
- Crs_MAX_BYTES_INSTITUTIONAL_CRS_COD);
+ sizeof (Crs->InstitutionalCrsCod) - 1);
}
/*****************************************************************************/
@@ -2261,8 +2254,7 @@ void Crs_RenameCourse (struct Crs_Course *Crs,Cns_ShrtOrFullName_t ShrtOrFullNam
CurrentCrsName,NewCrsName);
/* Change current course name in order to display it properly */
- Str_Copy (CurrentCrsName,NewCrsName,
- MaxBytes);
+ Str_Copy (CurrentCrsName,NewCrsName,MaxBytes);
}
}
else // The same name
@@ -2987,8 +2979,8 @@ static void Crs_EditingCourseConstructor (void)
Lay_ShowErrorAndExit ("Error initializing course.");
/***** Allocate memory for course *****/
- if ((Crs_EditingCrs = (struct Crs_Course *) malloc (sizeof (struct Crs_Course))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for course.");
+ if ((Crs_EditingCrs = malloc (sizeof (*Crs_EditingCrs))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/***** Reset course *****/
Crs_EditingCrs->CrsCod = -1L;
diff --git a/swad_cryptography.c b/swad_cryptography.c
index 7d37b288..6b2d23e8 100644
--- a/swad_cryptography.c
+++ b/swad_cryptography.c
@@ -148,8 +148,7 @@ void Cry_CreateUniqueNameEncrypted (char UniqueNameEncrypted[Cry_BYTES_ENCRYPTED
char UniqueNamePlain[Cns_MAX_BYTES_IP + Cns_MAX_DECIMAL_DIGITS_LONG + Cns_MAX_DECIMAL_DIGITS_LONG + Cns_MAX_DECIMAL_DIGITS_UINT + 1];
NumCall++;
- snprintf (UniqueNamePlain,sizeof (UniqueNamePlain),
- "%s-%lx-%x-%x",
+ snprintf (UniqueNamePlain,sizeof (UniqueNamePlain),"%s-%lx-%x-%x",
Gbl.IP,Gbl.StartExecutionTimeUTC,Gbl.PID,NumCall);
Cry_EncryptSHA256Base64 (UniqueNamePlain,UniqueNameEncrypted); // Make difficult to guess a unique name
}
diff --git a/swad_database.c b/swad_database.c
index b7b89919..45cb195a 100644
--- a/swad_database.c
+++ b/swad_database.c
@@ -4058,8 +4058,7 @@ void DB_ExitOnMySQLError (const char *Message)
{
char BigErrorMsg[64 * 1024];
- snprintf (BigErrorMsg,sizeof (BigErrorMsg),
- "Database error: %s (%s).",
+ snprintf (BigErrorMsg,sizeof (BigErrorMsg),"Database error: %s (%s).",
Message,mysql_error (&Gbl.mysql));
Lay_ShowErrorAndExit (BigErrorMsg);
}
diff --git a/swad_date.c b/swad_date.c
index e427981a..837149d9 100644
--- a/swad_date.c
+++ b/swad_date.c
@@ -309,8 +309,7 @@ bool Dat_GetDateFromYYYYMMDD (struct Date *Date,const char *YYYYMMDD)
if (YYYYMMDD[0])
if (sscanf (YYYYMMDD,"%04u%02u%02u",&(Date->Year),&(Date->Month),&(Date->Day)) == 3)
{
- Str_Copy (Date->YYYYMMDD,YYYYMMDD,
- Dat_LENGTH_YYYYMMDD);
+ Str_Copy (Date->YYYYMMDD,YYYYMMDD,sizeof (Date->YYYYMMDD) - 1);
return true;
}
@@ -415,22 +414,19 @@ void Dat_ConvDateToDateStr (const struct Date *Date,char StrDate[Cns_MAX_BYTES_D
switch (Gbl.Prefs.DateFormat)
{
case Dat_FORMAT_YYYY_MM_DD:
- snprintf (StrDate,Cns_MAX_BYTES_DATE + 1,
- "%04u-%02u-%02u",
+ snprintf (StrDate,Cns_MAX_BYTES_DATE + 1,"%04u-%02u-%02u",
Date->Year,
Date->Month,
Date->Day);
break;
case Dat_FORMAT_DD_MONTH_YYYY:
- snprintf (StrDate,Cns_MAX_BYTES_DATE + 1,
- "%u %s %04u",
+ snprintf (StrDate,Cns_MAX_BYTES_DATE + 1,"%u %s %04u",
Date->Day,
Txt_MONTHS_SMALL_SHORT[Date->Month - 1],
Date->Year);
break;
case Dat_FORMAT_MONTH_DD_YYYY:
- snprintf (StrDate,Cns_MAX_BYTES_DATE + 1,
- "%s %u, %04u",
+ snprintf (StrDate,Cns_MAX_BYTES_DATE + 1,"%s %u, %04u",
Txt_MONTHS_SMALL_SHORT[Date->Month - 1],
Date->Day,
Date->Year);
@@ -831,13 +827,11 @@ void Dat_GetBrowserTimeZone (char BrowserTimeZone[Dat_MAX_BYTES_TIME_ZONE + 1])
/* Convert from minutes to +-hh:mm */
// BrowserTimeZone must have space for strings in +hh:mm format (6 chars + \0)
if (ClientUTCMinusLocal > 0)
- snprintf (BrowserTimeZone,Dat_MAX_BYTES_TIME_ZONE + 1,
- "-%02u:%02u",
+ snprintf (BrowserTimeZone,Dat_MAX_BYTES_TIME_ZONE + 1,"-%02u:%02u",
(unsigned) ClientUTCMinusLocal / 60,
(unsigned) ClientUTCMinusLocal % 60);
else // ClientUTCMinusLocal <= 0
- snprintf (BrowserTimeZone,Dat_MAX_BYTES_TIME_ZONE + 1,
- "+%02u:%02u",
+ snprintf (BrowserTimeZone,Dat_MAX_BYTES_TIME_ZONE + 1,"+%02u:%02u",
(unsigned) (-ClientUTCMinusLocal) / 60,
(unsigned) (-ClientUTCMinusLocal) % 60);
}
@@ -1577,7 +1571,7 @@ void Dat_AssignDate (struct Date *DateDst,struct Date *DateSrc)
DateDst->Day = DateSrc->Day;
DateDst->Week = DateSrc->Week;
Str_Copy (DateDst->YYYYMMDD,DateSrc->YYYYMMDD,
- Dat_LENGTH_YYYYMMDD);
+ sizeof (DateDst->YYYYMMDD) - 1);
}
/*****************************************************************************/
diff --git a/swad_degree.c b/swad_degree.c
index 191fa077..0ea18ae6 100644
--- a/swad_degree.c
+++ b/swad_degree.c
@@ -464,8 +464,7 @@ static void Deg_ListDegreesForEdition (void)
}
else
{
- Str_Copy (WWW,Deg->WWW,
- Cns_MAX_BYTES_WWW);
+ Str_Copy (WWW,Deg->WWW,sizeof (WWW) - 1);
HTM_DIV_Begin ("class=\"EXTERNAL_WWW_SHORT\"");
HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"DAT\" title=\"%s\"",
Deg->WWW,Deg->WWW);
@@ -1081,7 +1080,7 @@ void Deg_GetListAllDegsWithStds (struct ListDegrees *Degs)
if (Degs->Num) // Degrees found...
{
/***** Create list with degrees *****/
- if ((Degs->Lst = (struct Deg_Degree *) calloc (Degs->Num,sizeof (struct Deg_Degree))) == NULL)
+ if ((Degs->Lst = calloc (Degs->Num,sizeof (*Degs->Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the degrees *****/
@@ -1126,8 +1125,8 @@ void Deg_GetListDegsInCurrentCtr (void)
Gbl.Hierarchy.Degs.Num = (unsigned) NumRows;
/***** Create list with degrees of this centre *****/
- if ((Gbl.Hierarchy.Degs.Lst = (struct Deg_Degree *) calloc (Gbl.Hierarchy.Degs.Num,
- sizeof (struct Deg_Degree))) == NULL)
+ if ((Gbl.Hierarchy.Degs.Lst = calloc (Gbl.Hierarchy.Degs.Num,
+ sizeof (*Gbl.Hierarchy.Degs.Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the degrees of this centre *****/
@@ -1388,16 +1387,13 @@ static void Deg_GetDataOfDegreeFromRow (struct Deg_Degree *Deg,MYSQL_ROW row)
Deg->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[4]);
/***** Get degree short name (row[5]) *****/
- Str_Copy (Deg->ShrtName,row[5],
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ Str_Copy (Deg->ShrtName,row[5],sizeof (Deg->ShrtName) - 1);
/***** Get degree full name (row[6]) *****/
- Str_Copy (Deg->FullName,row[6],
- Cns_HIERARCHY_MAX_BYTES_FULL_NAME);
+ Str_Copy (Deg->FullName,row[6],sizeof (Deg->FullName) - 1);
/***** Get WWW (row[7]) *****/
- Str_Copy (Deg->WWW,row[7],
- Cns_MAX_BYTES_WWW);
+ Str_Copy (Deg->WWW,row[7],sizeof (Deg->WWW) - 1);
}
/*****************************************************************************/
@@ -1420,8 +1416,7 @@ void Deg_GetShortNameOfDegreeByCod (struct Deg_Degree *Deg)
/***** Get the short name of this degree *****/
row = mysql_fetch_row (mysql_res);
- Str_Copy (Deg->ShrtName,row[0],
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ Str_Copy (Deg->ShrtName,row[0],sizeof (Deg->ShrtName) - 1);
}
/***** Free structure that stores the query result *****/
@@ -1537,11 +1532,10 @@ void Deg_RemoveDegreeCompletely (long DegCod)
Brw_RemoveDegFilesFromDB (DegCod);
/***** Remove directories of the degree *****/
- snprintf (PathDeg,sizeof (PathDeg),
- "%s/%02u/%u",
+ snprintf (PathDeg,sizeof (PathDeg),"%s/%02u/%u",
Cfg_PATH_DEG_PUBLIC,
(unsigned) (DegCod % 100),
- (unsigned) DegCod);
+ (unsigned) DegCod);
Fil_RemoveTree (PathDeg);
/***** Remove administrators of this degree *****/
@@ -1646,8 +1640,7 @@ void Deg_RenameDegree (struct Deg_Degree *Deg,Cns_ShrtOrFullName_t ShrtOrFullNam
CurrentDegName,NewDegName);
/* Change current degree name in order to display it properly */
- Str_Copy (CurrentDegName,NewDegName,
- MaxBytes);
+ Str_Copy (CurrentDegName,NewDegName,MaxBytes);
}
}
else // The same name
@@ -1748,8 +1741,7 @@ void Deg_ChangeDegWWW (void)
{
/***** Update the table changing old WWW by new WWW *****/
Deg_UpdateDegWWWDB (Deg_EditingDeg->DegCod,NewWWW);
- Str_Copy (Deg_EditingDeg->WWW,NewWWW,
- Cns_MAX_BYTES_WWW);
+ Str_Copy (Deg_EditingDeg->WWW,NewWWW,sizeof (Deg_EditingDeg->WWW) - 1);
/***** Write alert to show the change made
and put button to go to degree changed *****/
@@ -2179,8 +2171,8 @@ static void Deg_EditingDegreeConstructor (void)
Lay_ShowErrorAndExit ("Error initializing degree.");
/***** Allocate memory for degree *****/
- if ((Deg_EditingDeg = (struct Deg_Degree *) malloc (sizeof (struct Deg_Degree))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for degree.");
+ if ((Deg_EditingDeg = malloc (sizeof (*Deg_EditingDeg))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/***** Reset degree *****/
Deg_EditingDeg->DegCod = -1L;
diff --git a/swad_degree_config.c b/swad_degree_config.c
index ec1fce69..22a1b547 100644
--- a/swad_degree_config.c
+++ b/swad_degree_config.c
@@ -441,7 +441,7 @@ void DegCfg_ChangeDegWWW (void)
/***** Update the table changing old WWW by new WWW *****/
Deg_UpdateDegWWWDB (Gbl.Hierarchy.Deg.DegCod,NewWWW);
Str_Copy (Gbl.Hierarchy.Deg.WWW,NewWWW,
- Cns_MAX_BYTES_WWW);
+ sizeof (Gbl.Hierarchy.Deg.WWW) - 1);
/***** Write message to show the change made *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_The_new_web_address_is_X,
diff --git a/swad_degree_type.c b/swad_degree_type.c
index 94614d46..1eac5d31 100644
--- a/swad_degree_type.c
+++ b/swad_degree_type.c
@@ -695,9 +695,8 @@ void DT_GetListDegreeTypes (Hie_Lvl_Level_t Scope,DT_Order_t Order)
if (Gbl.DegTypes.Num)
{
/***** Create a list of degree types *****/
- if ((Gbl.DegTypes.Lst = (struct DegreeType *)
- calloc (Gbl.DegTypes.Num,
- sizeof (struct DegreeType))) == NULL)
+ if ((Gbl.DegTypes.Lst = calloc (Gbl.DegTypes.Num,
+ sizeof (*Gbl.DegTypes.Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get degree types *****/
@@ -714,7 +713,7 @@ void DT_GetListDegreeTypes (Hie_Lvl_Level_t Scope,DT_Order_t Order)
/* Get degree type name (row[1]) */
Str_Copy (Gbl.DegTypes.Lst[NumRow].DegTypName,row[1],
- Deg_MAX_BYTES_DEGREE_TYPE_NAME);
+ sizeof (Gbl.DegTypes.Lst[NumRow].DegTypName) - 1);
/* Number of degrees of this type (row[2]) */
if (sscanf (row[2],"%u",&Gbl.DegTypes.Lst[NumRow].NumDegs) != 1)
@@ -881,8 +880,7 @@ bool DT_GetDataOfDegreeTypeByCod (struct DegreeType *DegTyp)
row = mysql_fetch_row (mysql_res);
/* Get the name of the degree type (row[0]) */
- Str_Copy (DegTyp->DegTypName,row[0],
- Deg_MAX_BYTES_DEGREE_TYPE_NAME);
+ Str_Copy (DegTyp->DegTypName,row[0],sizeof (DegTyp->DegTypName) - 1);
/* Count number of degrees of this type */
DegTyp->NumDegs = DT_CountNumDegsOfType (DegTyp->DegTypCod);
@@ -1011,7 +1009,7 @@ void DT_RenameDegreeType (void)
/***** Set degree type name *****/
Str_Copy (DT_EditingDegTyp->DegTypName,NewNameDegTyp,
- Deg_MAX_BYTES_DEGREE_TYPE_NAME);
+ sizeof (DT_EditingDegTyp->DegTypName) - 1);
}
/*****************************************************************************/
@@ -1055,8 +1053,8 @@ static void DT_EditingDegreeTypeConstructor (void)
Lay_ShowErrorAndExit ("Error initializing degree type.");
/***** Allocate memory for degree type *****/
- if ((DT_EditingDegTyp = (struct DegreeType *) malloc (sizeof (struct DegreeType))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for degree type.");
+ if ((DT_EditingDegTyp = malloc (sizeof (*DT_EditingDegTyp))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/***** Reset degree type *****/
DT_EditingDegTyp->DegTypCod = -1L;
diff --git a/swad_department.c b/swad_department.c
index c93f388d..b462a0af 100644
--- a/swad_department.c
+++ b/swad_department.c
@@ -372,9 +372,8 @@ static void Dpt_GetListDepartments (struct Dpt_Departments *Departments,long Ins
if (Departments->Num) // Departments found...
{
/***** Create list with courses in degree *****/
- if ((Departments->Lst = (struct Dpt_Department *)
- calloc ((size_t) Departments->Num,
- sizeof (struct Dpt_Department))) == NULL)
+ if ((Departments->Lst = calloc (Departments->Num,
+ sizeof (*Departments->Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the departments *****/
@@ -396,16 +395,13 @@ static void Dpt_GetListDepartments (struct Dpt_Departments *Departments,long Ins
Lay_ShowErrorAndExit ("Wrong code of institution.");
/* Get the short name of the department (row[2]) */
- Str_Copy (Dpt->ShrtName,row[2],
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ Str_Copy (Dpt->ShrtName,row[2],sizeof (Dpt->ShrtName) - 1);
/* Get the full name of the department (row[3]) */
- Str_Copy (Dpt->FullName,row[3],
- Cns_HIERARCHY_MAX_BYTES_FULL_NAME);
+ Str_Copy (Dpt->FullName,row[3],sizeof (Dpt->FullName) - 1);
/* Get the URL of the department (row[4]) */
- Str_Copy (Dpt->WWW,row[4],
- Cns_MAX_BYTES_WWW);
+ Str_Copy (Dpt->WWW,row[4],sizeof (Dpt->WWW) - 1);
/* Get number of non-editing teachers and teachers in this department (row[5]) */
if (sscanf (row[5],"%u",&Dpt->NumTchs) != 1)
@@ -437,10 +433,8 @@ void Dpt_GetDataOfDepartmentByCod (struct Dpt_Department *Dpt)
/***** Check if department code is correct *****/
if (Dpt->DptCod == 0)
{
- Str_Copy (Dpt->ShrtName,Txt_Another_department,
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
- Str_Copy (Dpt->FullName,Txt_Another_department,
- Cns_HIERARCHY_MAX_BYTES_FULL_NAME);
+ Str_Copy (Dpt->ShrtName,Txt_Another_department,sizeof (Dpt->ShrtName) - 1);
+ Str_Copy (Dpt->FullName,Txt_Another_department,sizeof (Dpt->FullName) - 1);
}
else if (Dpt->DptCod > 0)
{
@@ -471,16 +465,13 @@ void Dpt_GetDataOfDepartmentByCod (struct Dpt_Department *Dpt)
Dpt->InsCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get the short name of the department (row[1]) */
- Str_Copy (Dpt->ShrtName,row[1],
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ Str_Copy (Dpt->ShrtName,row[1],sizeof (Dpt->ShrtName) - 1);
/* Get the full name of the department (row[2]) */
- Str_Copy (Dpt->FullName,row[2],
- Cns_HIERARCHY_MAX_BYTES_FULL_NAME);
+ Str_Copy (Dpt->FullName,row[2],sizeof (Dpt->FullName) - 1);
/* Get the URL of the department (row[3]) */
- Str_Copy (Dpt->WWW,row[3],
- Cns_MAX_BYTES_WWW);
+ Str_Copy (Dpt->WWW,row[3],sizeof (Dpt->WWW) - 1);
/* Get number of teachers in this department (row[4]) */
if (sscanf (row[4],"%u",&Dpt->NumTchs) != 1)
@@ -817,8 +808,7 @@ static void Dpt_RenameDepartment (Cns_ShrtOrFullName_t ShrtOrFullName)
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
/***** Update name *****/
- Str_Copy (CurrentDptName,NewDptName,
- MaxBytes);
+ Str_Copy (CurrentDptName,NewDptName,MaxBytes);
}
/*****************************************************************************/
@@ -886,8 +876,7 @@ void Dpt_ChangeDptWWW (void)
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
/***** Update web *****/
- Str_Copy (Dpt_EditingDpt->WWW,NewWWW,
- Cns_MAX_BYTES_WWW);
+ Str_Copy (Dpt_EditingDpt->WWW,NewWWW,sizeof (Dpt_EditingDpt->WWW) - 1);
}
/*****************************************************************************/
@@ -1197,8 +1186,8 @@ static void Dpt_EditingDepartmentConstructor (void)
Lay_ShowErrorAndExit ("Error initializing department.");
/***** Allocate memory for department *****/
- if ((Dpt_EditingDpt = (struct Dpt_Department *) malloc (sizeof (struct Dpt_Department))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for department.");
+ if ((Dpt_EditingDpt = malloc (sizeof (*Dpt_EditingDpt))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/***** Reset department *****/
Dpt_EditingDpt->DptCod = -1L;
diff --git a/swad_duplicate.c b/swad_duplicate.c
index 622f625d..3aa8a9b4 100644
--- a/swad_duplicate.c
+++ b/swad_duplicate.c
@@ -271,7 +271,7 @@ static void Dup_ListSimilarUsrs (void)
/***** Make query *****/
if (Gbl.Usrs.Other.UsrDat.Surname1[0] &&
- Gbl.Usrs.Other.UsrDat.FirstName[0]) // Name and surname 1 not empty
+ Gbl.Usrs.Other.UsrDat.FrstName[0]) // Name and surname 1 not empty
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get similar users",
"SELECT DISTINCT UsrCod FROM"
"(SELECT DISTINCT UsrCod FROM usr_IDs"
@@ -283,7 +283,7 @@ static void Dup_ListSimilarUsrs (void)
Gbl.Usrs.Other.UsrDat.UsrCod,
Gbl.Usrs.Other.UsrDat.Surname1,
Gbl.Usrs.Other.UsrDat.Surname2,
- Gbl.Usrs.Other.UsrDat.FirstName);
+ Gbl.Usrs.Other.UsrDat.FrstName);
else
NumUsrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get similar users",
"SELECT DISTINCT UsrCod FROM usr_IDs"
@@ -408,7 +408,7 @@ static void Dup_PutButtonToViewSimilarUsrs (const struct UsrData *UsrDat)
extern const char *Txt_Similar_users;
Frm_StartForm (ActLstSimUsr);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
Btn_PutConfirmButtonInline (Txt_Similar_users);
Frm_EndForm ();
}
@@ -422,7 +422,7 @@ static void Dup_PutButtonToEliminateUsrAccount (const struct UsrData *UsrDat)
extern const char *Txt_Eliminate_user_account;
Frm_StartForm (ActUpdOth);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
Par_PutHiddenParamUnsigned (NULL,"RegRemAction",(unsigned) Enr_ELIMINATE_ONE_USR_FROM_PLATFORM);
Btn_PutRemoveButtonInline (Txt_Eliminate_user_account);
Frm_EndForm ();
@@ -437,7 +437,7 @@ static void Dup_PutButtonToRemoveFromListOfDupUsrs (const struct UsrData *UsrDat
extern const char *Txt_Not_duplicated;
Frm_StartForm (ActRemDupUsr);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
Btn_PutConfirmButtonInline (Txt_Not_duplicated);
Frm_EndForm ();
}
diff --git a/swad_enrolment.c b/swad_enrolment.c
index 2d9fcd72..586f1119 100644
--- a/swad_enrolment.c
+++ b/swad_enrolment.c
@@ -571,7 +571,7 @@ void Enr_UpdateUsrData (struct UsrData *UsrDat)
"Comments='%s'"
" WHERE UsrCod=%ld",
UsrDat->Password,
- UsrDat->Surname1,UsrDat->Surname2,UsrDat->FirstName,
+ UsrDat->Surname1,UsrDat->Surname2,UsrDat->FrstName,
Usr_StringsSexDB[UsrDat->Sex],
UsrDat->CtyCod,
UsrDat->Phone[0],
@@ -1183,7 +1183,7 @@ static void Enr_ReceiveFormUsrsCrs (Rol_Role_t Role)
}
/***** Get list of users' IDs *****/
- if ((ListUsrsIDs = (char *) malloc (ID_MAX_BYTES_LIST_USRS_IDS + 1)) == NULL)
+ if ((ListUsrsIDs = malloc (ID_MAX_BYTES_LIST_USRS_IDS + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
Par_GetParToText ("UsrsIDs",ListUsrsIDs,ID_MAX_BYTES_LIST_USRS_IDS);
@@ -1248,7 +1248,7 @@ static void Enr_ReceiveFormUsrsCrs (Rol_Role_t Role)
/***** Find users for this user's ID *****/
ID_ReallocateListIDs (&UsrDat,1); // Only one user's ID
Str_Copy (UsrDat.IDs.List[0].ID,UsrDat.UsrIDNickOrEmail,
- ID_MAX_BYTES_USR_ID);
+ sizeof (UsrDat.IDs.List[0].ID) - 1);
Str_ConvertToUpperText (UsrDat.IDs.List[0].ID);
ID_GetListUsrCodsFromUsrID (&UsrDat,NULL,&ListUsrCods,false);
}
@@ -1375,7 +1375,7 @@ static void Enr_ReceiveFormUsrsCrs (Rol_Role_t Role)
/* Find users for this user's ID */
ID_ReallocateListIDs (&UsrDat,1); // Only one user's ID
Str_Copy (UsrDat.IDs.List[0].ID,UsrDat.UsrIDNickOrEmail,
- ID_MAX_BYTES_USR_ID);
+ sizeof (UsrDat.IDs.List[0].ID) - 1);
Str_ConvertToUpperText (UsrDat.IDs.List[0].ID);
ID_GetListUsrCodsFromUsrID (&UsrDat,NULL,&ListUsrCods,false);
}
@@ -2144,7 +2144,7 @@ void Enr_AskIfRejectSignUp (void)
/* End alert */
Ale_ShowAlertAndButton2 (ActRejSignUp,NULL,NULL,
- Usr_PutParamOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,
+ Usr_PutParamOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EnUsrCod,
Btn_REMOVE_BUTTON,Txt_Reject);
}
else
@@ -2919,7 +2919,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
}
Frm_StartForm (NextAction);
Crs_PutParamCrsCod (Crs.CrsCod);
- Usr_PutParamUsrCodEncrypted (UsrDat.EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat.EnUsrCod);
Btn_PutCreateButtonInline (Txt_Register);
Frm_EndForm ();
HTM_TD_End ();
@@ -2928,7 +2928,7 @@ static void Enr_ShowEnrolmentRequestsGivenRoles (unsigned RolesSelected)
HTM_TD_Begin ("class=\"DAT LT\"");
Frm_StartForm (ActReqRejSignUp);
Crs_PutParamCrsCod (Crs.CrsCod);
- Usr_PutParamUsrCodEncrypted (UsrDat.EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat.EnUsrCod);
Btn_PutRemoveButtonInline (Txt_Reject);
Frm_EndForm ();
HTM_TD_End ();
@@ -3657,7 +3657,7 @@ static void Enr_ReqAddAdm (Hie_Lvl_Level_t Scope,long Cod,const char *InsCtrDegN
/* End alert */
Ale_ShowAlertAndButton2 (Enr_ActNewAdm[Scope],NULL,NULL,
- Usr_PutParamOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,
+ Usr_PutParamOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EnUsrCod,
Btn_CREATE_BUTTON,Txt_Register_user_IN_A_COURSE_OR_DEGREE);
}
}
@@ -4075,7 +4075,7 @@ static void Enr_AskIfRemoveUsrFromCrs (struct UsrData *UsrDat)
break;
}
Frm_StartForm (NextAction);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
Pwd_AskForConfirmationOnDangerousAction ();
Btn_PutRemoveButton (ItsMe ? Txt_Remove_me_from_this_course :
Txt_Remove_user_from_this_course);
@@ -4227,7 +4227,7 @@ static void Enr_AskIfRemAdm (bool ItsMe,Hie_Lvl_Level_t Scope,
/* End alert */
Ale_ShowAlertAndButton2 (Enr_ActRemAdm[Scope],NULL,NULL,
- Usr_PutParamOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,
+ Usr_PutParamOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EnUsrCod,
Btn_REMOVE_BUTTON,
ItsMe ? Txt_Remove_me_as_an_administrator :
Txt_Remove_USER_as_an_administrator);
diff --git a/swad_exam.c b/swad_exam.c
index 4b16b1ba..2fd0f930 100644
--- a/swad_exam.c
+++ b/swad_exam.c
@@ -31,7 +31,6 @@
#include // For PATH_MAX
#include // For NULL
#include // For asprintf
-#include // For calloc
#include // For string functions
#include "swad_database.h"
@@ -853,7 +852,7 @@ void Exa_GetListExams (struct Exa_Exams *Exams,Exa_Order_t SelectedOrder)
Exams->Num = (unsigned) NumRows;
/***** Create list of exams *****/
- if ((Exams->Lst = (struct Exa_ExamSelected *) malloc (NumRows * sizeof (struct Exa_ExamSelected))) == NULL)
+ if ((Exams->Lst = malloc (NumRows * sizeof (*Exams->Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the exams codes *****/
@@ -890,7 +889,7 @@ void Exa_GetListSelectedExaCods (struct Exa_Exams *Exams)
/***** Allocate memory for list of exams selected *****/
MaxSizeListExaCodsSelected = Exams->Num * (Cns_MAX_DECIMAL_DIGITS_LONG + 1);
- if ((Exams->ExaCodsSelected = (char *) malloc (MaxSizeListExaCodsSelected + 1)) == NULL)
+ if ((Exams->ExaCodsSelected = malloc (MaxSizeListExaCodsSelected + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get parameter multiple with list of exams selected *****/
@@ -994,8 +993,7 @@ void Exa_GetDataOfExamByCod (struct Exa_Exam *Exam)
Exam->Visibility = TstVis_GetVisibilityFromStr (row[5]);
/* Get the title of the exam (row[6]) */
- Str_Copy (Exam->Title,row[6],
- Exa_MAX_BYTES_TITLE);
+ Str_Copy (Exam->Title,row[6],sizeof (Exam->Title) - 1);
/* Get number of sets */
Exam->NumSets = ExaSet_GetNumSetsExam (Exam->ExaCod);
@@ -1083,8 +1081,7 @@ void Exa_GetExamTxtFromDB (long ExaCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
{
/* Get info text */
row = mysql_fetch_row (mysql_res);
- Str_Copy (Txt,row[0],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Txt,row[0],Cns_MAX_BYTES_TEXT);
}
else
Txt[0] = '\0';
diff --git a/swad_exam_announcement.c b/swad_exam_announcement.c
index fb97e1aa..1516c40c 100644
--- a/swad_exam_announcement.c
+++ b/swad_exam_announcement.c
@@ -192,7 +192,7 @@ static long ExaAnn_GetParamsExamAnn (struct ExaAnn_ExamAnnouncements *ExamAnns)
// If the parameter is not present or is empty, initialize the string to the full name of the current course
if (!ExamAnns->ExamAnn.CrsFullName[0])
Str_Copy (ExamAnns->ExamAnn.CrsFullName,Gbl.Hierarchy.Crs.FullName,
- Cns_HIERARCHY_MAX_BYTES_FULL_NAME);
+ sizeof (ExamAnns->ExamAnn.CrsFullName) - 1);
/***** Get the year *****/
ExamAnns->ExamAnn.Year = (unsigned)
@@ -260,25 +260,25 @@ static long ExaAnn_GetParamsExamAnn (struct ExaAnn_ExamAnnouncements *ExamAnns)
static void ExaAnn_AllocMemExamAnn (struct ExaAnn_ExamAnnouncements *ExamAnns)
{
- if ((ExamAnns->ExamAnn.Place = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
+ if ((ExamAnns->ExamAnn.Place = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
- if ((ExamAnns->ExamAnn.Mode = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
+ if ((ExamAnns->ExamAnn.Mode = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
- if ((ExamAnns->ExamAnn.Structure = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
+ if ((ExamAnns->ExamAnn.Structure = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
- if ((ExamAnns->ExamAnn.DocRequired = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
+ if ((ExamAnns->ExamAnn.DocRequired = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
- if ((ExamAnns->ExamAnn.MatRequired = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
+ if ((ExamAnns->ExamAnn.MatRequired = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
- if ((ExamAnns->ExamAnn.MatAllowed = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
+ if ((ExamAnns->ExamAnn.MatAllowed = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
- if ((ExamAnns->ExamAnn.OtherInfo = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
+ if ((ExamAnns->ExamAnn.OtherInfo = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
}
@@ -896,7 +896,7 @@ void ExaAnn_CreateListExamAnns (struct ExaAnn_ExamAnnouncements *ExamAnns)
if (NumExaAnns)
{
/***** Allocate memory for the list *****/
- if ((ExamAnns->Lst = (struct ExaAnn_ExamCodeAndDate *) calloc (NumExaAnns,sizeof (struct ExaAnn_ExamCodeAndDate))) == NULL)
+ if ((ExamAnns->Lst = calloc (NumExaAnns,sizeof (*ExamAnns->Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the dates of the existing exam announcements *****/
@@ -984,7 +984,7 @@ static void ExaAnn_GetDataExamAnnFromDB (struct ExaAnn_ExamAnnouncements *ExamAn
/* Name of the course (row[2]) */
Str_Copy (ExamAnns->ExamAnn.CrsFullName,row[2],
- Cns_HIERARCHY_MAX_BYTES_FULL_NAME);
+ sizeof (ExamAnns->ExamAnn.CrsFullName) - 1);
/* Year (row[3]) */
if (sscanf (row[3],"%u",&ExamAnns->ExamAnn.Year) != 1)
@@ -992,7 +992,7 @@ static void ExaAnn_GetDataExamAnnFromDB (struct ExaAnn_ExamAnnouncements *ExamAn
/* Exam session (row[4]) */
Str_Copy (ExamAnns->ExamAnn.Session,row[4],
- ExaAnn_MAX_BYTES_SESSION);
+ sizeof (ExamAnns->ExamAnn.Session) - 1);
/* Date of exam announcement (row[5]) */
if (sscanf (row[5],"%04u-%02u-%02u %02u:%02u:%02u",
@@ -1013,8 +1013,8 @@ static void ExaAnn_GetDataExamAnnFromDB (struct ExaAnn_ExamAnnouncements *ExamAn
&ExamAnns->ExamAnn.StartTime.Minute,
&Second) != 6)
Lay_ShowErrorAndExit ("Wrong date of exam.");
- snprintf (ExamAnns->ExamAnn.ExamDate.YYYYMMDD,sizeof (ExamAnns->ExamAnn.ExamDate.YYYYMMDD),
- "%04u%02u%02u",
+ snprintf (ExamAnns->ExamAnn.ExamDate.YYYYMMDD,
+ sizeof (ExamAnns->ExamAnn.ExamDate.YYYYMMDD),"%04u%02u%02u",
ExamAnns->ExamAnn.ExamDate.Year,
ExamAnns->ExamAnn.ExamDate.Month,
ExamAnns->ExamAnn.ExamDate.Day);
@@ -1025,31 +1025,31 @@ static void ExaAnn_GetDataExamAnnFromDB (struct ExaAnn_ExamAnnouncements *ExamAn
/* Place (row[8]) */
Str_Copy (ExamAnns->ExamAnn.Place,row[8],
- Cns_MAX_BYTES_TEXT);
+ sizeof (ExamAnns->ExamAnn.Place) - 1);
/* Exam mode (row[9]) */
Str_Copy (ExamAnns->ExamAnn.Mode,row[9],
- Cns_MAX_BYTES_TEXT);
+ sizeof (ExamAnns->ExamAnn.Mode) - 1);
/* Structure (row[10]) */
Str_Copy (ExamAnns->ExamAnn.Structure,row[10],
- Cns_MAX_BYTES_TEXT);
+ sizeof (ExamAnns->ExamAnn.Structure) - 1);
/* Documentation required (row[11]) */
Str_Copy (ExamAnns->ExamAnn.DocRequired,row[11],
- Cns_MAX_BYTES_TEXT);
+ sizeof (ExamAnns->ExamAnn.DocRequired) - 1);
/* Material required (row[12]) */
Str_Copy (ExamAnns->ExamAnn.MatRequired,row[12],
- Cns_MAX_BYTES_TEXT);
+ sizeof (ExamAnns->ExamAnn.MatRequired) - 1);
/* Material allowed (row[13]) */
Str_Copy (ExamAnns->ExamAnn.MatAllowed,row[13],
- Cns_MAX_BYTES_TEXT);
+ sizeof (ExamAnns->ExamAnn.MatAllowed) - 1);
/* Other information for students (row[14]) */
Str_Copy (ExamAnns->ExamAnn.OtherInfo,row[14],
- Cns_MAX_BYTES_TEXT);
+ sizeof (ExamAnns->ExamAnn.OtherInfo) - 1);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
@@ -1726,14 +1726,12 @@ void ExaAnn_GetSummaryAndContentExamAnn (char SummaryStr[Ntf_MAX_BYTES_SUMMARY +
/***** Summary *****/
/* Name of the course and date of exam */
Dat_ConvDateToDateStr (&ExamAnns.ExamAnn.ExamDate,StrExamDate);
- snprintf (CrsNameAndDate,sizeof (CrsNameAndDate),
- "%s, %s, %2u:%02u",
+ snprintf (CrsNameAndDate,sizeof (CrsNameAndDate),"%s, %s, %2u:%02u",
ExamAnns.ExamAnn.CrsFullName,
StrExamDate,
ExamAnns.ExamAnn.StartTime.Hour,
ExamAnns.ExamAnn.StartTime.Minute);
- Str_Copy (SummaryStr,CrsNameAndDate,
- Ntf_MAX_BYTES_SUMMARY);
+ Str_Copy (SummaryStr,CrsNameAndDate,Ntf_MAX_BYTES_SUMMARY);
/***** Free memory of the exam announcement *****/
ExaAnn_FreeMemExamAnn (&ExamAnns);
diff --git a/swad_exam_log.c b/swad_exam_log.c
index 9c841b78..6e65617e 100644
--- a/swad_exam_log.c
+++ b/swad_exam_log.c
@@ -230,12 +230,11 @@ static void ExaLog_LogUsrAgent (long LogCod,long PrnCod)
MaxBytes = strlen (UserAgent) * Str_MAX_BYTES_PER_CHAR;
else
MaxBytes = 0;
- if ((UserAgentDB = (char *) malloc (MaxBytes + 1)) == NULL)
+ if ((UserAgentDB = malloc (MaxBytes + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
if (UserAgent)
{
- Str_Copy (UserAgentDB,UserAgent,
- MaxBytes);
+ Str_Copy (UserAgentDB,UserAgent,MaxBytes);
Str_ChangeFormat (Str_FROM_TEXT,Str_TO_TEXT,
UserAgentDB,MaxBytes,true);
}
@@ -379,16 +378,12 @@ void ExaLog_ShowExamLog (const struct ExaPrn_Print *Print)
ClickTimeUTC = Dat_GetUNIXTimeFromStr (row[3]);
/* Get IP (row[4]) */
- Str_Copy (IP,row[4],
- Cns_MAX_BYTES_IP);
+ Str_Copy (IP,row[4],sizeof (IP) - 1);
/* Get session id (row[5]) */
- if (row[5]) // This row has a user agent stored in database
- Str_Copy (SessionId,row[5],
- Cns_BYTES_SESSION_ID);
- else
- Str_Copy (SessionId,"=",
- Cns_BYTES_SESSION_ID);
+ Str_Copy (SessionId,row[5] ? row[5] : // This row has a user agent stored in database
+ "=",
+ sizeof (SessionId) - 1);
/* Get session id (row[6]) */
if (asprintf (&UserAgent,"%s",row[6] ? row[6] :
diff --git a/swad_exam_print.c b/swad_exam_print.c
index 0da4744f..8a90894e 100644
--- a/swad_exam_print.c
+++ b/swad_exam_print.c
@@ -29,7 +29,6 @@
#include // For PATH_MAX
#include // For NULL
#include // For asprintf
-#include // For calloc
#include // For string functions
#include "swad_box.h"
@@ -405,8 +404,7 @@ static void ExaPrn_GetQuestionsForNewPrintFromDB (struct ExaPrn_Print *Print,lon
Set.NumQstsToPrint = Str_ConvertStrToUnsigned (row[1]);
/* Get the title of the set (row[2]) */
- Str_Copy (Set.Title,row[2],
- ExaSet_MAX_BYTES_TITLE);
+ Str_Copy (Set.Title,row[2],sizeof (Set.Title) - 1);
/***** Questions in this set *****/
NumQstsFromSet = ExaPrn_GetSomeQstsFromSetToPrint (Print,&Set,&NumQstInPrint);
@@ -563,7 +561,7 @@ static void ExaPrn_GenerateChoiceIndexes (struct TstPrn_PrintedQuestion *Printed
else
snprintf (StrInd,sizeof (StrInd),",%u",Index);
Str_Concat (PrintedQuestion->StrIndexes,StrInd,
- Tst_MAX_BYTES_INDEXES_ONE_QST);
+ sizeof (PrintedQuestion->StrIndexes) - 1);
}
/***** Free structure that stores the query result *****/
@@ -648,11 +646,11 @@ void ExaPrn_GetPrintQuestionsFromDB (struct ExaPrn_Print *Print)
/* Get indexes for this question (row[3]) */
Str_Copy (Print->PrintedQuestions[NumQst].StrIndexes,row[3],
- Tst_MAX_BYTES_INDEXES_ONE_QST);
+ strlen (Print->PrintedQuestions[NumQst].StrIndexes) - 1);
/* Get answers selected by user for this question (row[4]) */
Str_Copy (Print->PrintedQuestions[NumQst].StrAnswers,row[4],
- Tst_MAX_BYTES_ANSWERS_ONE_QST);
+ strlen (Print->PrintedQuestions[NumQst].StrAnswers) - 1);
}
/***** Free structure that stores the query result *****/
@@ -870,13 +868,10 @@ static void ExaPrn_WriteIntAnsToFill (const struct ExaPrn_Print *Print,
char Id[3 + Cns_MAX_DECIMAL_DIGITS_UINT + 1]; // "Ansxx...x"
/***** Write input field for the answer *****/
- snprintf (Id,sizeof (Id),
- "Ans%010u",
- NumQst);
+ snprintf (Id,sizeof (Id),"Ans%010u",NumQst);
HTM_TxtF ("PrintedQuestions[NumQst].StrAnswers);
+ Id,Print->PrintedQuestions[NumQst].StrAnswers);
ExaPrn_WriteJSToUpdateExamPrint (Print,NumQst,Id,-1);
HTM_Txt (" />");
}
@@ -892,9 +887,7 @@ static void ExaPrn_WriteFltAnsToFill (const struct ExaPrn_Print *Print,
char Id[3 + Cns_MAX_DECIMAL_DIGITS_UINT + 1]; // "Ansxx...x"
/***** Write input field for the answer *****/
- snprintf (Id,sizeof (Id),
- "Ans%010u",
- NumQst);
+ snprintf (Id,sizeof (Id),"Ans%010u",NumQst);
HTM_TxtF (" initially all the answers will be blank.
If the user does not confirm the submission of their exam ==>
==> the exam may be half filled ==> the answers displayed will be those selected by the user. */
- snprintf (Id,sizeof (Id),
- "Ans%010u",
- NumQst);
+ snprintf (Id,sizeof (Id),"Ans%010u",NumQst);
HTM_TxtF ("");
@@ -968,9 +959,7 @@ static void ExaPrn_WriteChoAnsToFill (const struct ExaPrn_Print *Print,
If the user does not confirm the submission of their exam ==>
==> the exam may be half filled ==> the answers displayed will be those selected by the user. */
HTM_TD_Begin ("class=\"LT\"");
- snprintf (Id,sizeof (Id),
- "Ans%010u",
- NumQst);
+ snprintf (Id,sizeof (Id),"Ans%010u",NumQst);
HTM_TxtF ("Answer.Type == Tst_ANS_UNIQUE_CHOICE ? "radio" :
"checkbox",
@@ -1015,9 +1004,7 @@ static void ExaPrn_WriteTxtAnsToFill (const struct ExaPrn_Print *Print,
char Id[3 + Cns_MAX_DECIMAL_DIGITS_UINT + 1]; // "Ansxx...x"
/***** Write input field for the answer *****/
- snprintf (Id,sizeof (Id),
- "Ans%010u",
- NumQst);
+ snprintf (Id,sizeof (Id),"Ans%010u",NumQst);
HTM_TxtF ("Answer.Options[NumOpt].Text,row[0],
- Tst_MAX_BYTES_ANSWER_OR_FEEDBACK);
+ strlen (Question->Answer.Options[NumOpt].Text) - 1);
}
/***** Change format of answers text *****/
@@ -1457,8 +1444,7 @@ static void ExaPrn_GetAnswerFromDB (struct ExaPrn_Print *Print,long QstCod,
row = mysql_fetch_row (mysql_res);
/* Get answers selected by user for this question (row[0]) */
- Str_Copy (StrAnswers,row[0],
- Tst_MAX_BYTES_ANSWERS_ONE_QST);
+ Str_Copy (StrAnswers,row[0],strlen (StrAnswers) - 1);
}
else
StrAnswers[0] = '\0';
diff --git a/swad_exam_result.c b/swad_exam_result.c
index edc8aa70..1a09206b 100644
--- a/swad_exam_result.c
+++ b/swad_exam_result.c
@@ -29,7 +29,6 @@
#include // For PATH_MAX
#include // For NULL
#include // For asprintf
-#include // For calloc
#include // For string functions
#include "swad_action.h"
@@ -371,7 +370,7 @@ static void ExaRes_ListAllResultsInSelectedExams (struct Exa_Exams *Exams)
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,Gbl.Usrs.Other.UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Other.UsrDat);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS))
@@ -782,7 +781,7 @@ static void ExaRes_BuildExamsSelectedCommas (struct Exa_Exams *Exams,
/***** Allocate memory for subquery of exams selected *****/
MaxLength = (size_t) Exams->NumSelected * (Cns_MAX_DECIMAL_DIGITS_LONG + 1);
- if ((*ExamsSelectedCommas = (char *) malloc (MaxLength + 1)) == NULL)
+ if ((*ExamsSelectedCommas = malloc (MaxLength + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Build subquery with list of selected exams *****/
@@ -1164,7 +1163,7 @@ static void ExaRes_ShowResults (struct Exa_Exams *Exams,
case Usr_OTHER:
Frm_StartForm (ActSeeOneExaResOth);
ExaSes_PutParamsEdit (Exams);
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
break;
}
Ico_PutIconLink ("tasks.svg",Txt_Result);
@@ -1650,8 +1649,8 @@ void ExaRes_ShowExamResultUser (struct UsrData *UsrDat)
HTM_TxtF (" %s",UsrDat->Surname1);
if (UsrDat->Surname2[0])
HTM_TxtF (" %s",UsrDat->Surname2);
- if (UsrDat->FirstName[0])
- HTM_TxtF (", %s",UsrDat->FirstName);
+ if (UsrDat->FrstName[0])
+ HTM_TxtF (", %s",UsrDat->FrstName);
HTM_BR ();
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (UsrDat,PhotoURL);
Pho_ShowUsrPhoto (UsrDat,ShowPhoto ? PhotoURL :
diff --git a/swad_exam_session.c b/swad_exam_session.c
index 757656a2..8f211ddb 100644
--- a/swad_exam_session.c
+++ b/swad_exam_session.c
@@ -29,7 +29,6 @@
#include // For PATH_MAX
#include // For NULL
#include // For asprintf
-#include // For calloc
#include // For string functions
#include "swad_database.h"
@@ -268,8 +267,7 @@ void ExaSes_ListSessions (struct Exa_Exams *Exams,
Session->ExaCod = Exam->ExaCod;
Session->TimeUTC[Dat_START_TIME] = Gbl.StartExecutionTimeUTC; // Now
Session->TimeUTC[Dat_END_TIME ] = Gbl.StartExecutionTimeUTC + (1 * 60 * 60); // Now + 1 hour
- Str_Copy (Session->Title,Exam->Title,
- ExaSes_MAX_BYTES_TITLE);
+ Str_Copy (Session->Title,Exam->Title,sizeof (Session->Title) - 1);
/* Put form to create new session */
ExaSes_PutFormSession (Session); // Form to create session
@@ -890,8 +888,7 @@ static void ExaSes_GetSessionDataFromRow (MYSQL_RES *mysql_res,
/* Get the title of the session (row[7]) */
if (row[7])
- Str_Copy (Session->Title,row[7],
- ExaSes_MAX_BYTES_TITLE);
+ Str_Copy (Session->Title,row[7],sizeof (Session->Title) - 1);
else
Session->Title[0] = '\0';
diff --git a/swad_exam_set.c b/swad_exam_set.c
index 3146cb42..5e16e9d5 100644
--- a/swad_exam_set.c
+++ b/swad_exam_set.c
@@ -31,7 +31,6 @@
#include // For PATH_MAX
#include // For NULL
#include // For asprintf
-#include // For calloc
#include // For string functions
#include "swad_database.h"
@@ -242,16 +241,13 @@ void ExaSet_GetDataOfSetByCod (struct ExaSet_Set *Set)
/* Get set index (row[2]) */
Set->SetInd = Str_ConvertStrToUnsigned (row[2]);
- snprintf (StrSetInd,sizeof (Set->SetInd),
- "%u",
- Set->SetInd);
+ snprintf (StrSetInd,sizeof (Set->SetInd),"%u",Set->SetInd);
/* Get set index (row[3]) */
Set->NumQstsToPrint = Str_ConvertStrToUnsigned (row[3]);
/* Get the title of the set (row[4]) */
- Str_Copy (Set->Title,row[4],
- ExaSet_MAX_BYTES_TITLE);
+ Str_Copy (Set->Title,row[4],sizeof (Set->Title) - 1);
}
else
/* Initialize to empty set */
@@ -477,8 +473,7 @@ void ExaSet_ChangeSetTitle (void)
ExaSet_UpdateSetTitleDB (&Set,NewTitle);
/* Update title */
- Str_Copy (Set.Title,NewTitle,
- ExaSet_MAX_BYTES_TITLE);
+ Str_Copy (Set.Title,NewTitle,sizeof (Set.Title) - 1);
}
/***** Show current exam and its sets *****/
@@ -1085,16 +1080,13 @@ static void ExaSet_ListOneOrMoreSetsForEdition (struct Exa_Exams *Exams,
/* Get set index (row[1]) */
Set.SetInd = Str_ConvertStrToUnsigned (row[1]);
- snprintf (StrSetInd,sizeof (Set.SetInd),
- "%u",
- Set.SetInd);
+ snprintf (StrSetInd,sizeof (Set.SetInd),"%u",Set.SetInd);
/* Get number of questions to exam (row[2]) */
Set.NumQstsToPrint = Str_ConvertStrToUnsigned (row[2]);
/* Get the title of the set (row[3]) */
- Str_Copy (Set.Title,row[3],
- ExaSet_MAX_BYTES_TITLE);
+ Str_Copy (Set.Title,row[3],sizeof (Set.Title) - 1);
/* Initialize context */
Exams->SetCod = Set.SetCod;
@@ -1433,15 +1425,13 @@ void ExaSet_GetQstDataFromDB (struct Tst_Question *Question)
Question->Stem[0] = '\0';
if (row[3])
if (row[3][0])
- Str_Copy (Question->Stem,row[3],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Question->Stem,row[3],sizeof (Question->Stem) - 1);
/* Get the feedback (row[4]) */
Question->Feedback[0] = '\0';
if (row[4])
if (row[4][0])
- Str_Copy (Question->Feedback,row[4],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Question->Feedback,row[4],sizeof (Question->Feedback) - 1);
/* Get media (row[5]) */
Question->Media.MedCod = Str_ConvertStrCodToLongCod (row[5]);
@@ -1497,14 +1487,14 @@ void ExaSet_GetQstDataFromDB (struct Tst_Question *Question)
if (row[1])
if (row[1][0])
Str_Copy (Question->Answer.Options[NumOpt].Text,row[1],
- Tst_MAX_BYTES_ANSWER_OR_FEEDBACK);
+ sizeof (Question->Answer.Options[NumOpt].Text) - 1);
/* Get feedback (row[2]) */
Question->Answer.Options[NumOpt].Feedback[0] = '\0';
if (row[2])
if (row[2][0])
Str_Copy (Question->Answer.Options[NumOpt].Feedback,row[2],
- Tst_MAX_BYTES_ANSWER_OR_FEEDBACK);
+ sizeof (Question->Answer.Options[NumOpt].Feedback) - 1);
/* Get media (row[3]) */
Question->Answer.Options[NumOpt].Media.MedCod = Str_ConvertStrCodToLongCod (row[3]);
@@ -1679,7 +1669,7 @@ static void ExaSet_AllocateListSelectedQuestions (struct Exa_Exams *Exams)
{
if (!Exams->ListQuestions)
{
- if ((Exams->ListQuestions = (char *) malloc (ExaSet_MAX_BYTES_LIST_SELECTED_QUESTIONS + 1)) == NULL)
+ if ((Exams->ListQuestions = malloc (ExaSet_MAX_BYTES_LIST_SELECTED_QUESTIONS + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
Exams->ListQuestions[0] = '\0';
}
diff --git a/swad_figure.c b/swad_figure.c
index 5e0787e3..69f144a4 100644
--- a/swad_figure.c
+++ b/swad_figure.c
@@ -2584,27 +2584,21 @@ static void Fig_WriteRowStatsFileBrowsers1 (const char *NameOfFileZones,
Fil_WriteFileSizeFull ((double) SizeOfFileZones->Size,FileSizeStr);
if (SizeOfFileZones->NumCrss == -1) // Not applicable
- Str_Copy (StrNumCrss,"-",
- Cns_MAX_DECIMAL_DIGITS_UINT);
+ Str_Copy (StrNumCrss,"-",sizeof (StrNumCrss) - 1);
else
- snprintf (StrNumCrss,sizeof (StrNumCrss),
- "%d",
+ snprintf (StrNumCrss,sizeof (StrNumCrss),"%d",
SizeOfFileZones->NumCrss);
if (SizeOfFileZones->NumGrps == -1) // Not applicable
- Str_Copy (StrNumGrps,"-",
- Cns_MAX_DECIMAL_DIGITS_UINT);
+ Str_Copy (StrNumGrps,"-",sizeof (StrNumGrps) - 1);
else
- snprintf (StrNumGrps,sizeof (StrNumGrps),
- "%d",
+ snprintf (StrNumGrps,sizeof (StrNumGrps),"%d",
SizeOfFileZones->NumGrps);
if (SizeOfFileZones->NumUsrs == -1) // Not applicable
- Str_Copy (StrNumUsrs,"-",
- Cns_MAX_DECIMAL_DIGITS_UINT);
+ Str_Copy (StrNumUsrs,"-",sizeof (StrNumUsrs) - 1);
else
- snprintf (StrNumUsrs,sizeof (StrNumUsrs),
- "%d",
+ snprintf (StrNumUsrs,sizeof (StrNumUsrs),"%d",
SizeOfFileZones->NumUsrs);
HTM_TR_Begin (NULL);
@@ -2656,22 +2650,17 @@ static void Fig_WriteRowStatsFileBrowsers2 (const char *NameOfFileZones,
if (SizeOfFileZones->NumCrss == -1) // Not applicable
{
- Str_Copy (StrNumFoldersPerCrs,"-",
- Cns_MAX_DECIMAL_DIGITS_UINT);
- Str_Copy (StrNumFilesPerCrs,"-",
- Cns_MAX_DECIMAL_DIGITS_UINT);
- Str_Copy (FileSizePerCrsStr,"-",
- Fil_MAX_BYTES_FILE_SIZE_STRING);
+ Str_Copy (StrNumFoldersPerCrs,"-",sizeof (StrNumFoldersPerCrs) - 1);
+ Str_Copy (StrNumFilesPerCrs ,"-",sizeof (StrNumFilesPerCrs ) - 1);
+ Str_Copy (FileSizePerCrsStr ,"-",sizeof (FileSizePerCrsStr ) - 1);
}
else
{
- snprintf (StrNumFoldersPerCrs,sizeof (StrNumFoldersPerCrs),
- "%.1f",
+ snprintf (StrNumFoldersPerCrs,sizeof (StrNumFoldersPerCrs),"%.1f",
SizeOfFileZones->NumCrss ? (double) SizeOfFileZones->NumFolders /
(double) SizeOfFileZones->NumCrss :
0.0);
- snprintf (StrNumFilesPerCrs,sizeof (StrNumFilesPerCrs),
- "%.1f",
+ snprintf (StrNumFilesPerCrs,sizeof (StrNumFilesPerCrs),"%.1f",
SizeOfFileZones->NumCrss ? (double) SizeOfFileZones->NumFiles /
(double) SizeOfFileZones->NumCrss :
0.0);
@@ -2714,22 +2703,17 @@ static void Fig_WriteRowStatsFileBrowsers3 (const char *NameOfFileZones,
if (SizeOfFileZones->NumUsrs == -1) // Not applicable
{
- Str_Copy (StrNumFoldersPerUsr,"-",
- Cns_MAX_DECIMAL_DIGITS_UINT);
- Str_Copy (StrNumFilesPerUsr,"-",
- Cns_MAX_DECIMAL_DIGITS_UINT);
- Str_Copy (FileSizePerUsrStr,"-",
- Fil_MAX_BYTES_FILE_SIZE_STRING);
+ Str_Copy (StrNumFoldersPerUsr,"-",sizeof (StrNumFoldersPerUsr) - 1);
+ Str_Copy (StrNumFilesPerUsr ,"-",sizeof (StrNumFilesPerUsr ) - 1);
+ Str_Copy (FileSizePerUsrStr ,"-",sizeof (FileSizePerUsrStr ) - 1);
}
else
{
- snprintf (StrNumFoldersPerUsr,sizeof (StrNumFoldersPerUsr),
- "%.1f",
+ snprintf (StrNumFoldersPerUsr,sizeof (StrNumFoldersPerUsr),"%.1f",
SizeOfFileZones->NumUsrs ? (double) SizeOfFileZones->NumFolders /
(double) SizeOfFileZones->NumUsrs :
0.0);
- snprintf (StrNumFilesPerUsr,sizeof (StrNumFilesPerUsr),
- "%.1f",
+ snprintf (StrNumFilesPerUsr,sizeof (StrNumFilesPerUsr),"%.1f",
SizeOfFileZones->NumUsrs ? (double) SizeOfFileZones->NumFiles /
(double) SizeOfFileZones->NumUsrs :
0.0);
diff --git a/swad_file.c b/swad_file.c
index cfba462c..c112518a 100644
--- a/swad_file.c
+++ b/swad_file.c
@@ -78,8 +78,7 @@ void Fil_CreateFileForHTMLOutput (void)
/***** Create a unique name for the file *****/
snprintf (Gbl.HTMLOutput.FileName,sizeof (Gbl.HTMLOutput.FileName),
- "%s/%s.html",
- Cfg_PATH_OUT_PRIVATE,Gbl.UniqueNameEncrypted);
+ "%s/%s.html",Cfg_PATH_OUT_PRIVATE,Gbl.UniqueNameEncrypted);
/***** Open file for writing and reading *****/
if ((Gbl.F.Out = fopen (Gbl.HTMLOutput.FileName,"w+t")) == NULL)
@@ -322,14 +321,10 @@ void Fil_CreateUpdateFile (const char CurrentName[PATH_MAX + 1],
size_t LengthFileRoot = Str_GetLengthRootFileName (CurrentName);
char ErrorMsg[128 + PATH_MAX];
- Str_Copy (NewName,CurrentName,
- PATH_MAX);
+ Str_Copy (NewName,CurrentName,PATH_MAX);
NewName[LengthFileRoot] = '\0';
- snprintf (OldName,PATH_MAX + 1,
- "%s%s",
- NewName,ExtensionOldName);
- Str_Concat (NewName,".new",
- PATH_MAX);
+ snprintf (OldName,PATH_MAX + 1,"%s%s",NewName,ExtensionOldName);
+ Str_Concat (NewName,".new",PATH_MAX);
/* The new file shouldn't exist. If it exists is due to any error when running this CGI formerly
and the file was not renamed successfully. In this case, remove it! */
@@ -340,8 +335,7 @@ void Fil_CreateUpdateFile (const char CurrentName[PATH_MAX + 1],
if ((*NewFile = fopen (NewName,"wb")) == NULL)
{
snprintf (ErrorMsg,sizeof (ErrorMsg),
- "Can not create file %s.",
- NewName);
+ "Can not create file %s.",NewName);
Lay_ShowErrorAndExit (ErrorMsg);
}
}
@@ -402,8 +396,7 @@ void Fil_CreateDirIfNotExists (const char Path[PATH_MAX + 1])
if (mkdir (Path,(mode_t) 0xFFF) != 0)
{
snprintf (ErrorMsg,sizeof (ErrorMsg),
- "Can not create folder %s.",
- Path);
+ "Can not create folder %s.",Path);
Lay_ShowErrorAndExit (ErrorMsg);
}
}
@@ -445,8 +438,7 @@ void Fil_RemoveTree (const char Path[PATH_MAX + 1])
if (strcmp (FileList[NumFile]->d_name,".") &&
strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".."
{
- snprintf (PathFileRel,sizeof (PathFileRel),
- "%s/%s",
+ snprintf (PathFileRel,sizeof (PathFileRel),"%s/%s",
Path,FileList[NumFile]->d_name);
Fil_RemoveTree (PathFileRel);
}
@@ -466,8 +458,7 @@ void Fil_RemoveTree (const char Path[PATH_MAX + 1])
if (Error)
{
snprintf (ErrorMsg,sizeof (ErrorMsg),
- "Can not remove folder %s.",
- Path);
+ "Can not remove folder %s.",Path);
Lay_ShowErrorAndExit (ErrorMsg);
}
}
@@ -511,8 +502,7 @@ void Fil_RemoveOldTmpFiles (const char *Path,time_t TimeToRemove,
if (strcmp (FileList[NumFile]->d_name,".") &&
strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".."
{
- snprintf (Path2,sizeof (Path2),
- "%s/%s",
+ snprintf (Path2,sizeof (Path2),"%s/%s",
Path,FileList[NumFile]->d_name);
Fil_RemoveOldTmpFiles (Path2,TimeToRemove,true); // Recursive call
}
@@ -611,24 +601,19 @@ void Fil_WriteFileSizeBrief (double SizeInBytes,
char FileSizeStr[Fil_MAX_BYTES_FILE_SIZE_STRING + 1])
{
if (SizeInBytes < Ki)
- snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,
- "%.0f B",
+ snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,"%.0f B",
SizeInBytes);
else if (SizeInBytes < Mi)
- snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,
- "%.0f KiB",
+ snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,"%.0f KiB",
SizeInBytes / Ki);
else if (SizeInBytes < Gi)
- snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,
- "%.0f MiB",
+ snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,"%.0f MiB",
SizeInBytes / Mi);
else if (SizeInBytes < Ti)
- snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,
- "%.0f GiB",
+ snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,"%.0f GiB",
SizeInBytes / Gi);
else
- snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,
- "%.0f TiB",
+ snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,"%.0f TiB",
SizeInBytes / Ti);
}
@@ -636,23 +621,18 @@ void Fil_WriteFileSizeFull (double SizeInBytes,
char FileSizeStr[Fil_MAX_BYTES_FILE_SIZE_STRING + 1])
{
if (SizeInBytes < Ki)
- snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,
- "%.0f B",
+ snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,"%.0f B",
SizeInBytes);
else if (SizeInBytes < Mi)
- snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,
- "%.1f KiB",
+ snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,"%.1f KiB",
SizeInBytes / Ki);
else if (SizeInBytes < Gi)
- snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,
- "%.1f MiB",
+ snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,"%.1f MiB",
SizeInBytes / Mi);
else if (SizeInBytes < Ti)
- snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,
- "%.1f GiB",
+ snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,"%.1f GiB",
SizeInBytes / Gi);
else
- snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,
- "%.1f TiB",
+ snprintf (FileSizeStr,Fil_MAX_BYTES_FILE_SIZE_STRING + 1,"%.1f TiB",
SizeInBytes / Ti);
}
diff --git a/swad_file_browser.c b/swad_file_browser.c
index 51fd83dd..389a6444 100644
--- a/swad_file_browser.c
+++ b/swad_file_browser.c
@@ -2289,9 +2289,9 @@ static void Brw_GetDataCurrentGrp (void)
{
Gbl.Crs.Grps.GrpTyp.GrpTypCod = GrpDat.GrpTypCod;
Str_Copy (Gbl.Crs.Grps.GrpTyp.GrpTypName,GrpDat.GrpTypName,
- Grp_MAX_BYTES_GROUP_TYPE_NAME);
+ sizeof (Gbl.Crs.Grps.GrpTyp.GrpTypName) - 1);
Str_Copy (Gbl.Crs.Grps.GrpName,GrpDat.GrpName,
- Grp_MAX_BYTES_GROUP_NAME);
+ sizeof (Gbl.Crs.Grps.GrpName) - 1);
Gbl.Crs.Grps.MaxStudents = GrpDat.MaxStudents;
Gbl.Crs.Grps.Open = GrpDat.Open;
Gbl.Crs.Grps.FileZones = GrpDat.FileZones;
@@ -2345,7 +2345,7 @@ static void Brw_PutParamsFileBrowser (const char *PathInTree,const char *FilFolL
{
/***** Users selected *****/
Usr_PutHiddenParSelectedUsrsCods (&Gbl.Usrs.Selected);
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
}
/***** If full tree selected? *****/
@@ -2423,7 +2423,7 @@ static void Brw_GetParamsPathInTreeAndFileName (void)
if (Gbl.FileBrowser.Level == 1)
// We are in this case: assignments/assignment-folder
Str_Copy (Gbl.FileBrowser.Asg.Folder,Gbl.FileBrowser.FilFolLnk.Name,
- Brw_MAX_BYTES_FOLDER);
+ sizeof (Gbl.FileBrowser.Asg.Folder) - 1);
else
{
// We are in this case: assignments/assignment-folder/rest-of-path
@@ -2481,8 +2481,7 @@ static void Brw_SetPathFileBrowser (void)
/* Create a directory for all institutions which codes end in
institution-code mod 100 */
- snprintf (Path,sizeof (Path),
- "%s/%02u",
+ snprintf (Path,sizeof (Path),"%s/%02u",
Cfg_PATH_INS_PRIVATE,
(unsigned) (Gbl.Hierarchy.Ins.InsCod % 100));
Fil_CreateDirIfNotExists (Path);
@@ -2493,7 +2492,7 @@ static void Brw_SetPathFileBrowser (void)
"%s/%02u/%u",
Cfg_PATH_INS_PRIVATE,
(unsigned) (Gbl.Hierarchy.Ins.InsCod % 100),
- (unsigned) Gbl.Hierarchy.Ins.InsCod);
+ (unsigned) Gbl.Hierarchy.Ins.InsCod);
break;
case Brw_SHOW_DOC_CTR:
case Brw_ADMI_DOC_CTR:
@@ -2503,8 +2502,7 @@ static void Brw_SetPathFileBrowser (void)
/* Create a directory for all centres which codes end in
centre-code mod 100 */
- snprintf (Path,sizeof (Path),
- "%s/%02u",
+ snprintf (Path,sizeof (Path),"%s/%02u",
Cfg_PATH_CTR_PRIVATE,
(unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100));
Fil_CreateDirIfNotExists (Path);
@@ -2515,7 +2513,7 @@ static void Brw_SetPathFileBrowser (void)
"%s/%02u/%u",
Cfg_PATH_CTR_PRIVATE,
(unsigned) (Gbl.Hierarchy.Ctr.CtrCod % 100),
- (unsigned) Gbl.Hierarchy.Ctr.CtrCod);
+ (unsigned) Gbl.Hierarchy.Ctr.CtrCod);
break;
case Brw_SHOW_DOC_DEG:
case Brw_ADMI_DOC_DEG:
@@ -2525,8 +2523,7 @@ static void Brw_SetPathFileBrowser (void)
/* Create a directory for all degrees which codes end in
degree-code mod 100 */
- snprintf (Path,sizeof (Path),
- "%s/%02u",
+ snprintf (Path,sizeof (Path),"%s/%02u",
Cfg_PATH_DEG_PRIVATE,
(unsigned) (Gbl.Hierarchy.Deg.DegCod % 100));
Fil_CreateDirIfNotExists (Path);
@@ -2537,7 +2534,7 @@ static void Brw_SetPathFileBrowser (void)
"%s/%02u/%u",
Cfg_PATH_DEG_PRIVATE,
(unsigned) (Gbl.Hierarchy.Deg.DegCod % 100),
- (unsigned) Gbl.Hierarchy.Deg.DegCod);
+ (unsigned) Gbl.Hierarchy.Deg.DegCod);
break;
case Brw_SHOW_DOC_CRS:
case Brw_ADMI_DOC_CRS:
@@ -2546,9 +2543,8 @@ static void Brw_SetPathFileBrowser (void)
case Brw_SHOW_MRK_CRS:
case Brw_ADMI_MRK_CRS:
/* Create path to the current course */
- Str_Copy (Gbl.FileBrowser.Priv.PathAboveRootFolder,
- Gbl.Crs.PathPriv,
- PATH_MAX);
+ Str_Copy (Gbl.FileBrowser.Priv.PathAboveRootFolder,Gbl.Crs.PathPriv,
+ sizeof (Gbl.FileBrowser.Priv.PathAboveRootFolder) - 1);
break;
case Brw_SHOW_DOC_GRP:
case Brw_ADMI_DOC_GRP:
@@ -2557,73 +2553,62 @@ static void Brw_SetPathFileBrowser (void)
case Brw_SHOW_MRK_GRP:
case Brw_ADMI_MRK_GRP:
/* Create a directory for groups inside the current course */
- snprintf (Path,sizeof (Path),
- "%s/%s",
+ snprintf (Path,sizeof (Path),"%s/%s",
Gbl.Crs.PathPriv,Cfg_FOLDER_GRP);
Fil_CreateDirIfNotExists (Path);
/* Create path to this group */
- snprintf (Path,sizeof (Path),
- "%s/%s/%ld",
+ snprintf (Path,sizeof (Path),"%s/%s/%ld",
Gbl.Crs.PathPriv,Cfg_FOLDER_GRP,
Gbl.Crs.Grps.GrpCod);
- Str_Copy (Gbl.FileBrowser.Priv.PathAboveRootFolder,
- Path,
- PATH_MAX);
+ Str_Copy (Gbl.FileBrowser.Priv.PathAboveRootFolder,Path,
+ sizeof (Gbl.FileBrowser.Priv.PathAboveRootFolder) - 1);
break;
case Brw_ADMI_ASG_USR:
case Brw_ADMI_WRK_USR:
/* Create a directory for me inside the current course */
- snprintf (Path,sizeof (Path),
- "%s/%s",
+ snprintf (Path,sizeof (Path),"%s/%s",
Gbl.Crs.PathPriv,Cfg_FOLDER_USR);
Fil_CreateDirIfNotExists (Path);
/* Create a directory for all users whose codes end in
my-user-code mod 100 */
- snprintf (Path,sizeof (Path),
- "%s/%s/%02u",
+ snprintf (Path,sizeof (Path),"%s/%s/%02u",
Gbl.Crs.PathPriv,Cfg_FOLDER_USR,
(unsigned) (Gbl.Usrs.Me.UsrDat.UsrCod % 100));
Fil_CreateDirIfNotExists (Path);
/* Create path to me */
- snprintf (Path,sizeof (Path),
- "%s/%s/%02u/%ld",
+ snprintf (Path,sizeof (Path),"%s/%s/%02u/%ld",
Gbl.Crs.PathPriv,Cfg_FOLDER_USR,
(unsigned) (Gbl.Usrs.Me.UsrDat.UsrCod % 100),
Gbl.Usrs.Me.UsrDat.UsrCod);
- Str_Copy (Gbl.FileBrowser.Priv.PathAboveRootFolder,
- Path,
- PATH_MAX);
+ Str_Copy (Gbl.FileBrowser.Priv.PathAboveRootFolder,Path,
+ sizeof (Gbl.FileBrowser.Priv.PathAboveRootFolder) - 1);
break;
case Brw_ADMI_ASG_CRS:
case Brw_ADMI_WRK_CRS:
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
/* Create a directory for this user inside the current course */
- snprintf (Path,sizeof (Path),
- "%s/%s",
+ snprintf (Path,sizeof (Path),"%s/%s",
Gbl.Crs.PathPriv,Cfg_FOLDER_USR);
Fil_CreateDirIfNotExists (Path);
/* Create a directory for all users whose codes end in
user-code mod 100 */
- snprintf (Path,sizeof (Path),
- "%s/%s/%02u",
+ snprintf (Path,sizeof (Path),"%s/%s/%02u",
Gbl.Crs.PathPriv,Cfg_FOLDER_USR,
(unsigned) (Gbl.Usrs.Other.UsrDat.UsrCod % 100));
Fil_CreateDirIfNotExists (Path);
/* Create path to user */
- snprintf (Path,sizeof (Path),
- "%s/%s/%02u/%ld",
+ snprintf (Path,sizeof (Path),"%s/%s/%02u/%ld",
Gbl.Crs.PathPriv,Cfg_FOLDER_USR,
(unsigned) (Gbl.Usrs.Other.UsrDat.UsrCod % 100),
Gbl.Usrs.Other.UsrDat.UsrCod);
- Str_Copy (Gbl.FileBrowser.Priv.PathAboveRootFolder,
- Path,
- PATH_MAX);
+ Str_Copy (Gbl.FileBrowser.Priv.PathAboveRootFolder,Path,
+ sizeof (Gbl.FileBrowser.Priv.PathAboveRootFolder) - 1);
}
break;
case Brw_ADMI_DOC_PRJ:
@@ -2631,33 +2616,28 @@ static void Brw_SetPathFileBrowser (void)
PrjCod = Prj_GetPrjCod ();
/* Create a directory for projects inside the current course */
- snprintf (Path,sizeof (Path),
- "%s/%s",
+ snprintf (Path,sizeof (Path),"%s/%s",
Gbl.Crs.PathPriv,Cfg_FOLDER_PRJ);
Fil_CreateDirIfNotExists (Path);
/* Create a directory for all projects which codes end in
project-code mod 100 */
- snprintf (Path,sizeof (Path),
- "%s/%s/%02u",
+ snprintf (Path,sizeof (Path),"%s/%s/%02u",
Gbl.Crs.PathPriv,Cfg_FOLDER_PRJ,
(unsigned) (PrjCod % 100));
Fil_CreateDirIfNotExists (Path);
/* Create path to the current project */
- snprintf (Path,sizeof (Path),
- "%s/%s/%02u/%ld",
+ snprintf (Path,sizeof (Path),"%s/%s/%02u/%ld",
Gbl.Crs.PathPriv,Cfg_FOLDER_PRJ,
(unsigned) (PrjCod % 100),
PrjCod);
- Str_Copy (Gbl.FileBrowser.Priv.PathAboveRootFolder,
- Path,
- PATH_MAX);
+ Str_Copy (Gbl.FileBrowser.Priv.PathAboveRootFolder,Path,
+ sizeof (Gbl.FileBrowser.Priv.PathAboveRootFolder) - 1);
break;
case Brw_ADMI_BRF_USR:
- Str_Copy (Gbl.FileBrowser.Priv.PathAboveRootFolder,
- Gbl.Usrs.Me.PathDir,
- PATH_MAX);
+ Str_Copy (Gbl.FileBrowser.Priv.PathAboveRootFolder,Gbl.Usrs.Me.PathDir,
+ sizeof (Gbl.FileBrowser.Priv.PathAboveRootFolder) - 1);
break;
default:
return;
@@ -2667,13 +2647,11 @@ static void Brw_SetPathFileBrowser (void)
if (Gbl.FileBrowser.Priv.PathAboveRootFolder[0])
{
Fil_CreateDirIfNotExists (Gbl.FileBrowser.Priv.PathAboveRootFolder);
- snprintf (Path,sizeof (Path),
- "%s/%s",
+ snprintf (Path,sizeof (Path),"%s/%s",
Gbl.FileBrowser.Priv.PathAboveRootFolder,
Brw_RootFolderInternalNames[Gbl.FileBrowser.Type]);
- Str_Copy (Gbl.FileBrowser.Priv.PathRootFolder,
- Path,
- PATH_MAX);
+ Str_Copy (Gbl.FileBrowser.Priv.PathRootFolder,Path,
+ sizeof (Gbl.FileBrowser.Priv.PathRootFolder) - 1);
Fil_CreateDirIfNotExists (Gbl.FileBrowser.Priv.PathRootFolder);
/***** If file browser is for assignments,
@@ -2717,8 +2695,7 @@ bool Brw_CheckIfExistsFolderAssigmentForAnyUsr (const char *FolderName)
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/* Check if folder exists */
- snprintf (PathFolder,sizeof (PathFolder),
- "%s/usr/%02u/%ld/%s/%s",
+ snprintf (PathFolder,sizeof (PathFolder),"%s/usr/%02u/%ld/%s/%s",
Gbl.Crs.PathPriv,
(unsigned) (UsrCod % 100),
UsrCod, // User's code
@@ -2771,8 +2748,7 @@ static void Brw_CreateFoldersAssignmentsIfNotExist (long ZoneUsrCod)
if (row[0]) // Not necessary, because folder name is checked in query to be not empty
{
/* Create folder if not exists */
- snprintf (PathFolderAsg,sizeof (PathFolderAsg),
- "%s/%s",
+ snprintf (PathFolderAsg,sizeof (PathFolderAsg),"%s/%s",
Gbl.FileBrowser.Priv.PathRootFolder,row[0]);
Fil_CreateDirIfNotExists (PathFolderAsg);
}
@@ -2823,15 +2799,13 @@ bool Brw_UpdateFoldersAssigmentsIfExistForAllUsrs (const char *OldFolderName,con
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/* Rename folder if exists */
- snprintf (PathOldFolder,sizeof (PathOldFolder),
- "%s/usr/%02u/%ld/%s/%s",
+ snprintf (PathOldFolder,sizeof (PathOldFolder),"%s/usr/%02u/%ld/%s/%s",
Gbl.Crs.PathPriv,
(unsigned) (UsrCod % 100),
UsrCod, // User's code
Brw_INTERNAL_NAME_ROOT_FOLDER_ASSIGNMENTS,
OldFolderName);
- snprintf (PathNewFolder,sizeof (PathNewFolder),
- "%s/usr/%02u/%ld/%s/%s",
+ snprintf (PathNewFolder,sizeof (PathNewFolder),"%s/usr/%02u/%ld/%s/%s",
Gbl.Crs.PathPriv,
(unsigned) (UsrCod % 100),
UsrCod, // User's code
@@ -2855,8 +2829,7 @@ bool Brw_UpdateFoldersAssigmentsIfExistForAllUsrs (const char *OldFolderName,con
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/* Rename folder if exists */
- snprintf (PathOldFolder,sizeof (PathOldFolder),
- "%s/usr/%02u/%ld/%s/%s",
+ snprintf (PathOldFolder,sizeof (PathOldFolder),"%s/usr/%02u/%ld/%s/%s",
Gbl.Crs.PathPriv,
(unsigned) (UsrCod % 100),
UsrCod, // User's code
@@ -2864,8 +2837,7 @@ bool Brw_UpdateFoldersAssigmentsIfExistForAllUsrs (const char *OldFolderName,con
OldFolderName);
if (Fil_CheckIfPathExists (PathOldFolder))
{
- snprintf (PathNewFolder,sizeof (PathNewFolder),
- "%s/usr/%02u/%ld/%s/%s",
+ snprintf (PathNewFolder,sizeof (PathNewFolder),"%s/usr/%02u/%ld/%s/%s",
Gbl.Crs.PathPriv,
(unsigned) (UsrCod % 100),
UsrCod, // User's code
@@ -2883,11 +2855,9 @@ bool Brw_UpdateFoldersAssigmentsIfExistForAllUsrs (const char *OldFolderName,con
Brw_RemoveAffectedClipboards (Brw_ADMI_ASG_CRS,-1L,UsrCod);
/* Rename affected expanded folders */
- snprintf (OldPath,sizeof (OldPath),
- "%s/%s",
+ snprintf (OldPath,sizeof (OldPath),"%s/%s",
Brw_INTERNAL_NAME_ROOT_FOLDER_ASSIGNMENTS,OldFolderName);
- snprintf (NewPath,sizeof (NewPath),
- "%s/%s",
+ snprintf (NewPath,sizeof (NewPath),"%s/%s",
Brw_INTERNAL_NAME_ROOT_FOLDER_ASSIGNMENTS,NewFolderName);
Brw_RenameAffectedExpandedFolders (Brw_ADMI_ASG_USR,UsrCod,-1L,
OldPath,NewPath);
@@ -2948,8 +2918,7 @@ void Brw_RemoveFoldersAssignmentsIfExistForAllUsrs (const char *FolderName)
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/* Remove tree if exists */
- snprintf (PathFolder,sizeof (PathFolder),
- "%s/usr/%02u/%ld/%s/%s",
+ snprintf (PathFolder,sizeof (PathFolder),"%s/usr/%02u/%ld/%s/%s",
Gbl.Crs.PathPriv,
(unsigned) (UsrCod % 100),
UsrCod, // User's code
@@ -3225,7 +3194,7 @@ static void Brw_ShowFileBrowsersAsgWrkCrs (void)
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,Gbl.Usrs.Other.UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Other.UsrDat);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS))
@@ -3432,7 +3401,7 @@ static void Brw_ShowDataOwnerAsgWrk (struct UsrData *UsrDat)
break;
}
Frm_StartForm (NextAction);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
/***** Show user's ID *****/
ID_WriteUsrIDs (UsrDat,NULL);
@@ -3444,8 +3413,8 @@ static void Brw_ShowDataOwnerAsgWrk (struct UsrData *UsrDat)
HTM_Txt (UsrDat->Surname1);
if (UsrDat->Surname2[0])
HTM_TxtF (" %s",UsrDat->Surname2);
- if (UsrDat->FirstName[0])
- HTM_TxtF (", %s",UsrDat->FirstName);
+ if (UsrDat->FrstName[0])
+ HTM_TxtF (", %s",UsrDat->FrstName);
HTM_BUTTON_End ();
/***** Show user's email *****/
@@ -3697,8 +3666,7 @@ static void Brw_ShowFileBrowser (void)
/***** Begin box *****/
Gbl.FileBrowser.Id++;
snprintf (FileBrowserSectionId,sizeof (FileBrowserSectionId),
- "file_browser_%u",
- Gbl.FileBrowser.Id);
+ "file_browser_%u",Gbl.FileBrowser.Id);
HTM_SECTION_Begin (FileBrowserSectionId);
Box_BoxBegin ("100%",Brw_TitleOfFileBrowser[Gbl.FileBrowser.Type],
Brw_PutIconsFileBrowser,NULL,
@@ -3709,10 +3677,11 @@ static void Brw_ShowFileBrowser (void)
/***** List recursively the directory *****/
HTM_TABLE_Begin ("BROWSER_TABLE");
- Str_Copy (Gbl.FileBrowser.FilFolLnk.Path,Brw_RootFolderInternalNames[Gbl.FileBrowser.Type],
- PATH_MAX);
+ Str_Copy (Gbl.FileBrowser.FilFolLnk.Path,
+ Brw_RootFolderInternalNames[Gbl.FileBrowser.Type],
+ sizeof (Gbl.FileBrowser.FilFolLnk.Path) - 1);
Str_Copy (Gbl.FileBrowser.FilFolLnk.Name,".",
- NAME_MAX);
+ sizeof (Gbl.FileBrowser.FilFolLnk.Name) - 1);
Brw_SetFullPathInTree ();
Gbl.FileBrowser.FilFolLnk.Type = Brw_IS_FOLDER;
if (Brw_WriteRowFileBrowser (0,"1",
@@ -3983,76 +3952,62 @@ static void Brw_WriteSubtitleOfFileBrowser (void)
switch (Gbl.FileBrowser.Type)
{
case Brw_SHOW_DOC_INS:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_only_for_reading_by_students_and_teachers_of_the_institution);
break;
case Brw_ADMI_DOC_INS:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_for_reading_and_writing_by_administrators_of_the_institution);
break;
case Brw_ADMI_SHR_INS:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_for_reading_and_writing_by_students_and_teachers_of_the_institution);
break;
case Brw_SHOW_DOC_CTR:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_only_for_reading_by_students_and_teachers_of_the_centre);
break;
case Brw_ADMI_DOC_CTR:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_for_reading_and_writing_by_administrators_of_the_centre);
break;
case Brw_ADMI_SHR_CTR:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_for_reading_and_writing_by_students_and_teachers_of_the_centre);
break;
case Brw_SHOW_DOC_DEG:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_only_for_reading_by_students_and_teachers_of_the_degree);
break;
case Brw_ADMI_DOC_DEG:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_for_reading_and_writing_by_administrators_of_the_degree);
break;
case Brw_ADMI_SHR_DEG:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_for_reading_and_writing_by_students_and_teachers_of_the_degree);
break;
case Brw_SHOW_DOC_CRS:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_only_for_reading_by_students_and_teachers_of_the_course);
break;
case Brw_SHOW_DOC_GRP:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_only_for_reading_by_students_of_the_group_and_teachers_of_the_course);
break;
case Brw_ADMI_DOC_CRS:
case Brw_ADMI_DOC_GRP:
case Brw_ADMI_TCH_CRS:
case Brw_ADMI_TCH_GRP:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_for_reading_and_writing_by_teachers_of_the_course);
break;
case Brw_ADMI_SHR_CRS:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_for_reading_and_writing_by_students_and_teachers_of_the_course);
break;
case Brw_ADMI_SHR_GRP:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_for_reading_and_writing_by_students_of_the_group_and_teachers_of_the_course);
break;
case Brw_SHOW_MRK_CRS:
@@ -4060,15 +4015,13 @@ static void Brw_WriteSubtitleOfFileBrowser (void)
switch (Gbl.Usrs.Me.Role.Logged)
{
case Rol_STD:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_only_for_reading_by_you_and_the_teachers_of_the_course);
break;
case Rol_NET:
case Rol_TCH:
case Rol_SYS_ADM:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_the_marks_of_a_student_chosen_at_random_);
break;
default:
@@ -4079,36 +4032,30 @@ static void Brw_WriteSubtitleOfFileBrowser (void)
break;
case Brw_ADMI_MRK_CRS:
case Brw_ADMI_MRK_GRP:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_for_reading_and_writing_by_teachers_of_the_course);
break;
case Brw_ADMI_ASG_USR:
case Brw_ADMI_WRK_USR:
- snprintf (Subtitle,sizeof (Subtitle),
- "%s
(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"%s
(%s)",
Gbl.Usrs.Me.UsrDat.FullName,
Txt_accessible_for_reading_and_writing_by_you_and_the_teachers_of_the_course);
break;
case Brw_ADMI_ASG_CRS:
case Brw_ADMI_WRK_CRS:
- snprintf (Subtitle,sizeof (Subtitle),
- "%s",
+ snprintf (Subtitle,sizeof (Subtitle),"%s",
Gbl.Usrs.Other.UsrDat.FullName);
break;
case Brw_ADMI_DOC_PRJ:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_for_reading_and_writing_by_project_members);
break;
case Brw_ADMI_ASS_PRJ:
- snprintf (Subtitle,sizeof (Subtitle),
- "(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"(%s)",
Txt_accessible_for_reading_and_writing_by_project_tutors_and_evaluators);
break;
case Brw_ADMI_BRF_USR:
- snprintf (Subtitle,sizeof (Subtitle),
- "%s
(%s)",
+ snprintf (Subtitle,sizeof (Subtitle),"%s
(%s)",
Gbl.Usrs.Me.UsrDat.FullName,
Txt_nobody_else_can_access_this_content);
break;
@@ -5118,21 +5065,18 @@ void Brw_CreateDirDownloadTmp (void)
/* 1b: rest of chars */
if (NumDir)
snprintf (Gbl.FileBrowser.TmpPubDir.R,sizeof (Gbl.FileBrowser.TmpPubDir.R),
- "%s_%u",
- &Gbl.UniqueNameEncrypted[2],NumDir);
+ "%s_%u",&Gbl.UniqueNameEncrypted[2],NumDir);
else
Str_Copy (Gbl.FileBrowser.TmpPubDir.R,&Gbl.UniqueNameEncrypted[2],
- NAME_MAX);
+ sizeof (Gbl.FileBrowser.TmpPubDir.R) - 1);
/* 2. Create the left directory */
- snprintf (PathUniqueDirL,sizeof (PathUniqueDirL),
- "%s/%s",
+ snprintf (PathUniqueDirL,sizeof (PathUniqueDirL),"%s/%s",
Cfg_PATH_FILE_BROWSER_TMP_PUBLIC,Gbl.FileBrowser.TmpPubDir.L);
Fil_CreateDirIfNotExists (PathUniqueDirL);
/* 3. Create the right directory inside the left one */
- snprintf (PathUniqueDirR,sizeof (PathUniqueDirR),
- "%s/%s",
+ snprintf (PathUniqueDirR,sizeof (PathUniqueDirR),"%s/%s",
PathUniqueDirL,Gbl.FileBrowser.TmpPubDir.R);
if (mkdir (PathUniqueDirR,(mode_t) 0xFFF))
Lay_ShowErrorAndExit ("Can not create a temporary folder for download.");
@@ -5338,8 +5282,7 @@ static void Brw_CalcSizeOfDirRecursive (unsigned Level,char *Path)
Gbl.FileBrowser.Size.NumLevls++;
/* Update counters depending on whether it's a directory or a regular file */
- snprintf (PathFileRel,sizeof (PathFileRel),
- "%s/%s",
+ snprintf (PathFileRel,sizeof (PathFileRel),"%s/%s",
Path,FileList[NumFile]->d_name);
if (lstat (PathFileRel,&FileStatus)) // On success ==> 0 is returned
Lay_ShowErrorAndExit ("Can not get information about a file or folder.");
@@ -5397,24 +5340,20 @@ static void Brw_ListDir (unsigned Level,const char *ParentRowId,
strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".."
{
/***** Construct the full path of the file or folder *****/
- snprintf (PathFileRel,sizeof (PathFileRel),
- "%s/%s",
+ snprintf (PathFileRel ,sizeof (PathFileRel ),"%s/%s",
Path ,FileList[NumFile]->d_name);
- snprintf (PathFileInExplTree,sizeof (PathFileInExplTree),
- "%s/%s",
+ snprintf (PathFileInExplTree,sizeof (PathFileInExplTree),"%s/%s",
PathInTree,FileList[NumFile]->d_name);
Str_Copy (Gbl.FileBrowser.FilFolLnk.Path,PathInTree,
- PATH_MAX);
+ sizeof (Gbl.FileBrowser.FilFolLnk.Path) - 1);
Str_Copy (Gbl.FileBrowser.FilFolLnk.Name,FileList[NumFile]->d_name,
- NAME_MAX);
+ sizeof (Gbl.FileBrowser.FilFolLnk.Name) - 1);
Brw_SetFullPathInTree ();
/***** Add number of row to parent row id *****/
NumRow++;
- snprintf (RowId,sizeof (RowId),
- "%s_%u",
- ParentRowId,NumRow);
+ snprintf (RowId,sizeof (RowId),"%s_%u",ParentRowId,NumRow);
/***** Get file or folder status *****/
if (lstat (PathFileRel,&FileStatus)) // On success ==> 0 is returned
@@ -5515,8 +5454,7 @@ static bool Brw_WriteRowFileBrowser (unsigned Level,const char *RowId,
/***** Initializations *****/
Gbl.FileBrowser.Clipboard.IsThisFile = false;
- snprintf (FileBrowserId,sizeof (FileBrowserId),
- "fil_brw_%u",
+ snprintf (FileBrowserId,sizeof (FileBrowserId),"fil_brw_%u",
Gbl.FileBrowser.Id);
/***** Is this row hidden or visible? *****/
@@ -5576,7 +5514,7 @@ static bool Brw_WriteRowFileBrowser (unsigned Level,const char *RowId,
if (Level == 1) // Main folder of the assignment
{
Str_Copy (Gbl.FileBrowser.Asg.Folder,Gbl.FileBrowser.FilFolLnk.Name,
- Brw_MAX_BYTES_FOLDER);
+ sizeof (Gbl.FileBrowser.Asg.Folder) - 1);
Asg_GetDataOfAssignmentByFolder (&Gbl.FileBrowser.Asg);
// The data of this assignment remains in Gbl.FileBrowser.Asg
// for all subsequent rows with Level > 1 (files or folders inside this folder),
@@ -5730,15 +5668,14 @@ void Brw_SetFullPathInTree (void)
Gbl.FileBrowser.FilFolLnk.Full[0] = '\0';
else if (strcmp (Gbl.FileBrowser.FilFolLnk.Name,"."))
{
- snprintf (FullPath,sizeof (FullPath),
- "%s/%s",
+ snprintf (FullPath,sizeof (FullPath),"%s/%s",
Gbl.FileBrowser.FilFolLnk.Path,Gbl.FileBrowser.FilFolLnk.Name);
Str_Copy (Gbl.FileBrowser.FilFolLnk.Full,FullPath,
- PATH_MAX);
+ sizeof (Gbl.FileBrowser.FilFolLnk.Full) - 1);
}
else // It's the root folder
Str_Copy (Gbl.FileBrowser.FilFolLnk.Full,Gbl.FileBrowser.FilFolLnk.Path,
- PATH_MAX);
+ sizeof (Gbl.FileBrowser.FilFolLnk.Full) - 1);
}
/*****************************************************************************/
@@ -5772,8 +5709,7 @@ static bool Brw_CheckIfCanPasteIn (unsigned Level)
if (Gbl.FileBrowser.Clipboard.IsThisTree) // We are in the same tree of the clipboard ==> we can paste or not depending on the subtree
{
/***** Construct the name of the file or folder destination *****/
- snprintf (PathDstWithFile,sizeof (PathDstWithFile),
- "%s/%s",
+ snprintf (PathDstWithFile,sizeof (PathDstWithFile),"%s/%s",
Gbl.FileBrowser.FilFolLnk.Full,
Gbl.FileBrowser.Clipboard.FilFolLnk.Name);
@@ -6403,8 +6339,7 @@ static void Brw_GetFileNameToShow (Brw_FileType_t FileType,
char FileNameToShow[NAME_MAX + 1])
{
/***** Copy file name *****/
- Str_Copy (FileNameToShow,FileName,
- NAME_MAX);
+ Str_Copy (FileNameToShow,FileName,NAME_MAX);
/***** Remove .url if link *****/
if (FileType == Brw_IS_LINK) // It's a link (URL inside a .url file)
@@ -6421,8 +6356,7 @@ void Brw_CreateTmpPublicLinkToPrivateFile (const char *FullPathIncludingFile,
char Link[PATH_MAX + 1];
/***** Create, into temporary public directory, a symbolic link to file *****/
- snprintf (Link,sizeof (Link),
- "%s/%s/%s/%s",
+ snprintf (Link,sizeof (Link),"%s/%s/%s/%s",
Cfg_PATH_FILE_BROWSER_TMP_PUBLIC,
Gbl.FileBrowser.TmpPubDir.L,
Gbl.FileBrowser.TmpPubDir.R,
@@ -6618,8 +6552,7 @@ void Brw_RemFileFromTree (void)
if (Brw_CheckIfICanEditFileOrFolder (Gbl.FileBrowser.Level)) // Can I remove this file?
{
- snprintf (Path,sizeof (Path),
- "%s/%s",
+ snprintf (Path,sizeof (Path),"%s/%s",
Gbl.FileBrowser.Priv.PathAboveRootFolder,
Gbl.FileBrowser.FilFolLnk.Full);
@@ -6672,8 +6605,7 @@ void Brw_RemFolderFromTree (void)
if (Brw_CheckIfICanEditFileOrFolder (Gbl.FileBrowser.Level)) // Can I remove this folder?
{
- snprintf (Path,sizeof (Path),
- "%s/%s",
+ snprintf (Path,sizeof (Path),"%s/%s",
Gbl.FileBrowser.Priv.PathAboveRootFolder,
Gbl.FileBrowser.FilFolLnk.Full);
@@ -6741,8 +6673,7 @@ void Brw_RemSubtreeInFileBrowser (void)
if (Brw_CheckIfICanEditFileOrFolder (Gbl.FileBrowser.Level)) // Can I remove this subtree?
{
- snprintf (Path,sizeof (Path),
- "%s/%s",
+ snprintf (Path,sizeof (Path),"%s/%s",
Gbl.FileBrowser.Priv.PathAboveRootFolder,
Gbl.FileBrowser.FilFolLnk.Full);
@@ -7137,7 +7068,7 @@ static bool Brw_GetMyClipboard (void)
/* Get file path (row[4]) */
Str_Copy (Gbl.FileBrowser.Clipboard.FilFolLnk.Full,row[4],
- PATH_MAX);
+ sizeof (Gbl.FileBrowser.Clipboard.FilFolLnk.Full) - 1);
Str_SplitFullPathIntoPathAndFileName (Gbl.FileBrowser.Clipboard.FilFolLnk.Full,
Gbl.FileBrowser.Clipboard.FilFolLnk.Path,
Gbl.FileBrowser.Clipboard.FilFolLnk.Name);
@@ -7334,8 +7265,7 @@ static void Brw_InsFoldersInPathAndUpdOtherFoldersInExpandedFolders (const char
*/
/***** Make a copy to keep Path unchanged *****/
- Str_Copy (CopyOfPath,Path,
- PATH_MAX);
+ Str_Copy (CopyOfPath,Path,sizeof (CopyOfPath) - 1);
/***** Insert paths in table of expanded folders if they are not yet there *****/
do
@@ -7884,8 +7814,7 @@ static void Brw_PasteClipboard (void)
case Brw_ADMI_SHR_INS:
Hie.Ins.InsCod = Gbl.FileBrowser.Clipboard.Cod;
if (Ins_GetDataOfInstitutionByCod (&Hie.Ins))
- snprintf (PathOrg,sizeof (PathOrg),
- "%s/%02u/%u/%s",
+ snprintf (PathOrg,sizeof (PathOrg),"%s/%02u/%u/%s",
Cfg_PATH_INS_PRIVATE,
(unsigned) (Hie.Ins.InsCod % 100),
(unsigned) Hie.Ins.InsCod,
@@ -7897,8 +7826,7 @@ static void Brw_PasteClipboard (void)
case Brw_ADMI_SHR_CTR:
Hie.Ctr.CtrCod = Gbl.FileBrowser.Clipboard.Cod;
if (Ctr_GetDataOfCentreByCod (&Hie.Ctr))
- snprintf (PathOrg,sizeof (PathOrg),
- "%s/%02u/%u/%s",
+ snprintf (PathOrg,sizeof (PathOrg),"%s/%02u/%u/%s",
Cfg_PATH_CTR_PRIVATE,
(unsigned) (Hie.Ctr.CtrCod % 100),
(unsigned) Hie.Ctr.CtrCod,
@@ -7910,8 +7838,7 @@ static void Brw_PasteClipboard (void)
case Brw_ADMI_SHR_DEG:
Hie.Deg.DegCod = Gbl.FileBrowser.Clipboard.Cod;
if (Deg_GetDataOfDegreeByCod (&Hie.Deg))
- snprintf (PathOrg,sizeof (PathOrg),
- "%s/%02u/%u/%s",
+ snprintf (PathOrg,sizeof (PathOrg),"%s/%02u/%u/%s",
Cfg_PATH_DEG_PRIVATE,
(unsigned) (Hie.Deg.DegCod % 100),
(unsigned) Hie.Deg.DegCod,
@@ -7925,8 +7852,7 @@ static void Brw_PasteClipboard (void)
case Brw_ADMI_MRK_CRS:
Hie.Crs.CrsCod = Gbl.FileBrowser.Clipboard.Cod;
if (Crs_GetDataOfCourseByCod (&Hie.Crs))
- snprintf (PathOrg,sizeof (PathOrg),
- "%s/%ld/%s",
+ snprintf (PathOrg,sizeof (PathOrg),"%s/%ld/%s",
Cfg_PATH_CRS_PRIVATE,Hie.Crs.CrsCod,
Gbl.FileBrowser.Clipboard.FilFolLnk.Full);
else
@@ -7940,8 +7866,7 @@ static void Brw_PasteClipboard (void)
Grp_GetDataOfGroupByCod (&GrpDat);
Hie.Crs.CrsCod = GrpDat.CrsCod;
if (Crs_GetDataOfCourseByCod (&Hie.Crs))
- snprintf (PathOrg,sizeof (PathOrg),
- "%s/%ld/%s/%ld/%s",
+ snprintf (PathOrg,sizeof (PathOrg),"%s/%ld/%s/%ld/%s",
Cfg_PATH_CRS_PRIVATE,Hie.Crs.CrsCod,Cfg_FOLDER_GRP,
GrpDat.GrpCod,
Gbl.FileBrowser.Clipboard.FilFolLnk.Full);
@@ -7956,8 +7881,7 @@ static void Brw_PasteClipboard (void)
Usr_UsrDataConstructor (&UsrDat);
UsrDat.UsrCod = Gbl.FileBrowser.Clipboard.WorksUsrCod;
Usr_GetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS); // Check that user exists
- snprintf (PathOrg,sizeof (PathOrg),
- "%s/%ld/%s/%02u/%ld/%s",
+ snprintf (PathOrg,sizeof (PathOrg),"%s/%ld/%s/%02u/%ld/%s",
Cfg_PATH_CRS_PRIVATE,Hie.Crs.CrsCod,Cfg_FOLDER_USR,
(unsigned) (Gbl.FileBrowser.Clipboard.WorksUsrCod % 100),
Gbl.FileBrowser.Clipboard.WorksUsrCod,
@@ -7971,8 +7895,7 @@ static void Brw_PasteClipboard (void)
case Brw_ADMI_WRK_USR:
Hie.Crs.CrsCod = Gbl.FileBrowser.Clipboard.Cod;
if (Crs_GetDataOfCourseByCod (&Hie.Crs))
- snprintf (PathOrg,sizeof (PathOrg),
- "%s/%ld/%s/%02u/%ld/%s",
+ snprintf (PathOrg,sizeof (PathOrg),"%s/%ld/%s/%02u/%ld/%s",
Cfg_PATH_CRS_PRIVATE,Hie.Crs.CrsCod,Cfg_FOLDER_USR,
(unsigned) (Gbl.Usrs.Me.UsrDat.UsrCod % 100),
Gbl.Usrs.Me.UsrDat.UsrCod,
@@ -7985,8 +7908,7 @@ static void Brw_PasteClipboard (void)
PrjCod = Gbl.FileBrowser.Clipboard.Cod;
Hie.Crs.CrsCod = Prj_GetCourseOfProject (PrjCod);
if (Crs_GetDataOfCourseByCod (&Hie.Crs))
- snprintf (PathOrg,sizeof (PathOrg),
- "%s/%ld/%s/%02u/%ld/%s",
+ snprintf (PathOrg,sizeof (PathOrg),"%s/%ld/%s/%02u/%ld/%s",
Cfg_PATH_CRS_PRIVATE,Hie.Crs.CrsCod,Cfg_FOLDER_PRJ,
(unsigned) (PrjCod % 100),
PrjCod,
@@ -7995,8 +7917,7 @@ static void Brw_PasteClipboard (void)
Lay_ShowErrorAndExit ("The copy source does not exist.");
break;
case Brw_ADMI_BRF_USR:
- snprintf (PathOrg,sizeof (PathOrg),
- "%s/%s",
+ snprintf (PathOrg,sizeof (PathOrg),"%s/%s",
Gbl.Usrs.Me.PathDir,
Gbl.FileBrowser.Clipboard.FilFolLnk.Full);
break;
@@ -8142,16 +8063,14 @@ static bool Brw_PasteTreeIntoFolder (unsigned LevelOrg,
// for example "sha"
// ==> do not copy the root folder itself into destination
Str_Copy (PathDstInTreeWithFile,PathDstInTree,
- PATH_MAX);
+ sizeof (PathDstInTreeWithFile) - 1);
else // Origin of copy is a file or folder inside the root folder
// for example "sha/folder1/file1"
- snprintf (PathDstInTreeWithFile,sizeof (PathDstInTreeWithFile),
- "%s/%s",
+ snprintf (PathDstInTreeWithFile,sizeof (PathDstInTreeWithFile),"%s/%s",
PathDstInTree,FileNameOrg);
/***** Construct the relative path of the destination file or folder *****/
- snprintf (PathDstWithFile,sizeof (PathDstWithFile),
- "%s/%s",
+ snprintf (PathDstWithFile,sizeof (PathDstWithFile),"%s/%s",
Gbl.FileBrowser.Priv.PathAboveRootFolder,
PathDstInTreeWithFile);
@@ -8287,8 +8206,7 @@ static bool Brw_PasteTreeIntoFolder (unsigned LevelOrg,
strcmp (FileList[NumFile]->d_name,".") &&
strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".."
{
- snprintf (PathInFolderOrg,sizeof (PathInFolderOrg),
- "%s/%s",
+ snprintf (PathInFolderOrg,sizeof (PathInFolderOrg),"%s/%s",
PathOrg,FileList[NumFile]->d_name);
/* Recursive call to this function */
if (!Brw_PasteTreeIntoFolder (LevelOrg + 1,
@@ -8625,17 +8543,14 @@ void Brw_RecFolderFileBrowser (void)
if (Str_ConvertFilFolLnkNameToValid (Gbl.FileBrowser.NewFilFolLnkName))
{
/* In Gbl.FileBrowser.NewFilFolLnkName is the name of the new folder */
- snprintf (Path,sizeof (Path),
- "%s/%s",
+ snprintf (Path,sizeof (Path),"%s/%s",
Gbl.FileBrowser.Priv.PathAboveRootFolder,
Gbl.FileBrowser.FilFolLnk.Full);
if (strlen (Path) + 1 + strlen (Gbl.FileBrowser.NewFilFolLnkName) > PATH_MAX)
Lay_ShowErrorAndExit ("Path is too long.");
- Str_Concat (Path,"/",
- PATH_MAX);
- Str_Concat (Path,Gbl.FileBrowser.NewFilFolLnkName,
- PATH_MAX);
+ Str_Concat (Path,"/",sizeof (Path) - 1);
+ Str_Concat (Path,Gbl.FileBrowser.NewFilFolLnkName,sizeof (Path) - 1);
/* Create the new directory */
if (mkdir (Path,(mode_t) 0xFFF) == 0)
@@ -8660,7 +8575,8 @@ void Brw_RecFolderFileBrowser (void)
Brw_InsFoldersInPathAndUpdOtherFoldersInExpandedFolders (Gbl.FileBrowser.FilFolLnk.Full);
/* Add entry to the table of files/folders */
- snprintf (PathCompleteInTreeIncludingFolder,sizeof (PathCompleteInTreeIncludingFolder),
+ snprintf (PathCompleteInTreeIncludingFolder,
+ sizeof (PathCompleteInTreeIncludingFolder),
"%s/%s",
Gbl.FileBrowser.FilFolLnk.Full,
Gbl.FileBrowser.NewFilFolLnkName);
@@ -8729,28 +8645,22 @@ void Brw_RenFolderFileBrowser (void)
if (strcmp (Gbl.FileBrowser.FilFolLnk.Name,Gbl.FileBrowser.NewFilFolLnkName)) // The name has changed
{
/* Gbl.FileBrowser.FilFolLnk.Name holds the new name of the folder */
- snprintf (OldPathInTree,sizeof (OldPathInTree),
- "%s/%s",
+ snprintf (OldPathInTree,sizeof (OldPathInTree),"%s/%s",
Gbl.FileBrowser.FilFolLnk.Path,
Gbl.FileBrowser.FilFolLnk.Name);
- snprintf (OldPath,sizeof (OldPath),
- "%s/%s",
- Gbl.FileBrowser.Priv.PathAboveRootFolder,
- OldPathInTree);
+ snprintf (OldPath,sizeof (OldPath),"%s/%s",
+ Gbl.FileBrowser.Priv.PathAboveRootFolder,OldPathInTree);
/* Gbl.FileBrowser.NewFilFolLnkName holds the new name of the folder */
if (strlen (Gbl.FileBrowser.Priv.PathAboveRootFolder) + 1 +
strlen (Gbl.FileBrowser.FilFolLnk.Path) + 1 +
strlen (Gbl.FileBrowser.NewFilFolLnkName) > PATH_MAX)
Lay_ShowErrorAndExit ("Path is too long.");
- snprintf (NewPathInTree,sizeof (NewPathInTree),
- "%s/%s",
+ snprintf (NewPathInTree,sizeof (NewPathInTree),"%s/%s",
Gbl.FileBrowser.FilFolLnk.Path,
Gbl.FileBrowser.NewFilFolLnkName);
- snprintf (NewPath,sizeof (NewPath),
- "%s/%s",
- Gbl.FileBrowser.Priv.PathAboveRootFolder,
- NewPathInTree);
+ snprintf (NewPath,sizeof (NewPath),"%s/%s",
+ Gbl.FileBrowser.Priv.PathAboveRootFolder,NewPathInTree);
/* We should check here that a folder with the same name does not exist.
but we leave this work to the system */
@@ -8915,18 +8825,15 @@ static bool Brw_RcvFileInFileBrw (Brw_UploadType_t UploadType)
if (Str_ConvertFilFolLnkNameToValid (Gbl.FileBrowser.NewFilFolLnkName))
{
/* Gbl.FileBrowser.NewFilFolLnkName holds the name of the new file */
- snprintf (Path,sizeof (Path),
- "%s/%s",
+ snprintf (Path,sizeof (Path),"%s/%s",
Gbl.FileBrowser.Priv.PathAboveRootFolder,
Gbl.FileBrowser.FilFolLnk.Full);
if (strlen (Path) + 1 +
strlen (Gbl.FileBrowser.NewFilFolLnkName) +
strlen (".tmp") > PATH_MAX)
Lay_ShowErrorAndExit ("Path is too long.");
- Str_Concat (Path,"/",
- PATH_MAX);
- Str_Concat (Path,Gbl.FileBrowser.NewFilFolLnkName,
- PATH_MAX);
+ Str_Concat (Path,"/",sizeof (Path) - 1);
+ Str_Concat (Path,Gbl.FileBrowser.NewFilFolLnkName,sizeof (Path) - 1);
/* Check if the destination file exists */
if (Fil_CheckIfPathExists (Path))
@@ -8936,9 +8843,7 @@ static bool Brw_RcvFileInFileBrw (Brw_UploadType_t UploadType)
else // Destination file does not exist
{
/* End receiving the file */
- snprintf (PathTmp,sizeof (PathTmp),
- "%s.tmp",
- Path);
+ snprintf (PathTmp,sizeof (PathTmp),"%s.tmp",Path);
FileIsValid = Fil_EndReceptionOfFile (PathTmp,Param); // Gbl.Alert.Txt contains feedback text
/* Check if the content of the file of marks is valid */
@@ -9094,7 +8999,7 @@ void Brw_RecLinkFileBrowser (void)
File in swad: intel-architectures.pdf.url
*/
Str_Copy (URLWithoutEndingSlash,Gbl.FileBrowser.NewFilFolLnkName,
- PATH_MAX);
+ sizeof (URLWithoutEndingSlash) - 1);
else
/*
Gbl.FileBrowser.NewFilFolLnkName is empty
@@ -9104,7 +9009,7 @@ void Brw_RecLinkFileBrowser (void)
File in swad: 64-ia-32-architectures-software-developer-manual-325462.pdf.url
*/
Str_Copy (URLWithoutEndingSlash,URL,
- PATH_MAX);
+ sizeof (URLWithoutEndingSlash) - 1);
/* Remove possible final '/' from URL */
if (URLWithoutEndingSlash[LengthURL - 1] == '/')
@@ -9119,18 +9024,14 @@ void Brw_RecLinkFileBrowser (void)
if (Str_ConvertFilFolLnkNameToValid (FileName)) // Gbl.Alert.Txt contains feedback text
{
/* The name of the file with the link will be the FileName.url */
- snprintf (Path,sizeof (Path),
- "%s/%s",
+ snprintf (Path,sizeof (Path),"%s/%s",
Gbl.FileBrowser.Priv.PathAboveRootFolder,
Gbl.FileBrowser.FilFolLnk.Full);
if (strlen (Path) + 1 + strlen (FileName) + strlen (".url") > PATH_MAX)
Lay_ShowErrorAndExit ("Path is too long.");
- Str_Concat (Path,"/",
- PATH_MAX);
- Str_Concat (Path,FileName,
- PATH_MAX);
- Str_Concat (Path,".url",
- PATH_MAX);
+ Str_Concat (Path,"/",sizeof (Path) - 1);
+ Str_Concat (Path,FileName,sizeof (Path) - 1);
+ Str_Concat (Path,".url",sizeof (Path) - 1);
/* Check if the URL file exists */
if (Fil_CheckIfPathExists (Path))
@@ -9170,8 +9071,7 @@ void Brw_RecLinkFileBrowser (void)
snprintf (PathCompleteInTreeIncludingFile,
sizeof (PathCompleteInTreeIncludingFile),
"%s/%s.url",
- Gbl.FileBrowser.FilFolLnk.Full,
- FileName);
+ Gbl.FileBrowser.FilFolLnk.Full,FileName);
FilCod = Brw_AddPathToDB (Gbl.Usrs.Me.UsrDat.UsrCod,Brw_IS_LINK,
PathCompleteInTreeIncludingFile,false,Brw_LICENSE_DEFAULT);
@@ -10070,9 +9970,9 @@ static void Brw_WriteBigLinkToDownloadFile (const char *URL,
Frm_StartForm (Gbl.FileBrowser.Type == Brw_SHOW_MRK_CRS ? ActSeeMyMrkCrs :
ActSeeMyMrkGrp);
Str_Copy (Gbl.FileBrowser.FilFolLnk.Path,FileMetadata->FilFolLnk.Path,
- PATH_MAX);
+ sizeof (Gbl.FileBrowser.FilFolLnk.Path) - 1);
Str_Copy (Gbl.FileBrowser.FilFolLnk.Name,FileMetadata->FilFolLnk.Name,
- NAME_MAX);
+ sizeof (Gbl.FileBrowser.FilFolLnk.Name) - 1);
Gbl.FileBrowser.FilFolLnk.Type = FileMetadata->FilFolLnk.Type;
Brw_PutImplicitParamsFileBrowser (&Gbl.FileBrowser.FilFolLnk);
@@ -10121,9 +10021,9 @@ static void Brw_WriteSmallLinkToDownloadFile (const char *URL,
Frm_StartForm (Gbl.FileBrowser.Type == Brw_SHOW_MRK_CRS ? ActSeeMyMrkCrs :
ActSeeMyMrkGrp);
Str_Copy (Gbl.FileBrowser.FilFolLnk.Path,FileMetadata->FilFolLnk.Path,
- PATH_MAX);
+ sizeof (Gbl.FileBrowser.FilFolLnk.Path) - 1);
Str_Copy (Gbl.FileBrowser.FilFolLnk.Name,FileMetadata->FilFolLnk.Name,
- NAME_MAX);
+ sizeof (Gbl.FileBrowser.FilFolLnk.Name) - 1);
Gbl.FileBrowser.FilFolLnk.Type = FileMetadata->FilFolLnk.Type;
Brw_PutImplicitParamsFileBrowser (&Gbl.FileBrowser.FilFolLnk);
@@ -10158,10 +10058,8 @@ void Brw_GetLinkToDownloadFile (const char *PathInTree,const char *FileName,char
char URLWithSpaces[PATH_MAX + 1];
/***** Construct absolute path to file in the private directory *****/
- snprintf (FullPathIncludingFile,sizeof (FullPathIncludingFile),
- "%s/%s/%s",
- Gbl.FileBrowser.Priv.PathAboveRootFolder,
- PathInTree,FileName);
+ snprintf (FullPathIncludingFile,sizeof (FullPathIncludingFile),"%s/%s/%s",
+ Gbl.FileBrowser.Priv.PathAboveRootFolder,PathInTree,FileName);
if (Str_FileIs (FileName,"url")) // It's a link (URL inside a .url file)
{
@@ -10183,8 +10081,7 @@ void Brw_GetLinkToDownloadFile (const char *PathInTree,const char *FileName,char
Brw_CreateTmpPublicLinkToPrivateFile (FullPathIncludingFile,FileName);
/***** Create URL pointing to symbolic link *****/
- snprintf (URLWithSpaces,sizeof (URLWithSpaces),
- "%s/%s/%s/%s",
+ snprintf (URLWithSpaces,sizeof (URLWithSpaces),"%s/%s/%s/%s",
Cfg_URL_FILE_BROWSER_TMP_PUBLIC,
Gbl.FileBrowser.TmpPubDir.L,
Gbl.FileBrowser.TmpPubDir.R,
@@ -10429,7 +10326,7 @@ void Brw_GetFileMetadataByPath (struct FileMetadata *FileMetadata)
/* Get path (row[6]) */
Str_Copy (FileMetadata->FilFolLnk.Full,row[6],
- PATH_MAX);
+ sizeof (FileMetadata->FilFolLnk.Full) - 1);
Str_SplitFullPathIntoPathAndFileName (FileMetadata->FilFolLnk.Full,
FileMetadata->FilFolLnk.Path,
FileMetadata->FilFolLnk.Name);
@@ -10558,7 +10455,7 @@ void Brw_GetFileMetadataByCod (struct FileMetadata *FileMetadata)
/* Get path (row[6]) */
Str_Copy (FileMetadata->FilFolLnk.Full,row[6],
- PATH_MAX);
+ sizeof (FileMetadata->FilFolLnk.Full) - 1);
Str_SplitFullPathIntoPathAndFileName (FileMetadata->FilFolLnk.Full,
FileMetadata->FilFolLnk.Path,
FileMetadata->FilFolLnk.Name);
@@ -10647,8 +10544,7 @@ bool Brw_GetFileTypeSizeAndDate (struct FileMetadata *FileMetadata)
char Path[PATH_MAX + 1 + PATH_MAX + 1];
struct stat FileStatus;
- snprintf (Path,sizeof (Path),
- "%s/%s",
+ snprintf (Path,sizeof (Path),"%s/%s",
Gbl.FileBrowser.Priv.PathAboveRootFolder,
FileMetadata->FilFolLnk.Full);
if (lstat (Path,&FileStatus)) // On success ==> 0 is returned
@@ -11731,8 +11627,7 @@ void Brw_RemoveGrpZones (long CrsCod,long GrpCod)
Brw_RemoveGrpFilesFromDB (GrpCod);
/***** Remove group zones *****/
- snprintf (PathGrpFileZones,sizeof (PathGrpFileZones),
- "%s/%ld/grp/%ld",
+ snprintf (PathGrpFileZones,sizeof (PathGrpFileZones),"%s/%ld/grp/%ld",
Cfg_PATH_CRS_PRIVATE,CrsCod,GrpCod);
Fil_RemoveTree (PathGrpFileZones);
}
@@ -11749,8 +11644,7 @@ void Brw_RemoveUsrWorksInCrs (struct UsrData *UsrDat,struct Crs_Course *Crs)
Brw_RemoveWrkFilesFromDB (Crs->CrsCod,UsrDat->UsrCod);
/***** Remove the folder for this user inside the course *****/
- snprintf (PathUsrInCrs,sizeof (PathUsrInCrs),
- "%s/%ld/usr/%02u/%ld",
+ snprintf (PathUsrInCrs,sizeof (PathUsrInCrs),"%s/%ld/usr/%02u/%ld",
Cfg_PATH_CRS_PRIVATE,Crs->CrsCod,
(unsigned) (UsrDat->UsrCod % 100),UsrDat->UsrCod);
Fil_RemoveTree (PathUsrInCrs);
@@ -11818,8 +11712,7 @@ void Brw_GetSummaryAndContentOfFile (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
Brw_GetFileMetadataByCod (&FileMetadata);
/***** Copy file name into summary string *****/
- Str_Copy (SummaryStr,FileMetadata.FilFolLnk.Name,
- Ntf_MAX_BYTES_SUMMARY);
+ Str_Copy (SummaryStr,FileMetadata.FilFolLnk.Name,Ntf_MAX_BYTES_SUMMARY);
/***** Copy some file metadata into content string *****/
if (GetContent && ContentStr)
@@ -12360,11 +12253,9 @@ static void Brw_ScanDirRemovingOldFiles (unsigned Level,
strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".."
{
/***** Construct the full path of the file or folder *****/
- snprintf (PathFileRel,sizeof (PathFileRel),
- "%s/%s",
+ snprintf (PathFileRel,sizeof (PathFileRel),"%s/%s",
Path,FileList[NumFile]->d_name);
- snprintf (PathFileInExplTree,sizeof (PathFileInExplTree),
- "%s/%s",
+ snprintf (PathFileInExplTree,sizeof (PathFileInExplTree),"%s/%s",
PathInTree,FileList[NumFile]->d_name);
/***** Get file or folder status *****/
diff --git a/swad_follow.c b/swad_follow.c
index 38e64d24..233a7753 100644
--- a/swad_follow.c
+++ b/swad_follow.c
@@ -557,7 +557,7 @@ void Fol_ShowFollowingAndFollowers (const struct UsrData *UsrDat,
{
Frm_StartForm (IFollowUsr ? ActUnfUsr :
ActFolUsr);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_INPUT_IMAGE (Cfg_URL_ICON_PUBLIC,
IFollowUsr ? "user-check.svg" :
"user-plus.svg",
@@ -598,7 +598,7 @@ static void Fol_ShowNumberOfFollowingOrFollowers (const struct UsrData *UsrDat,
{
/* Form to list users */
Frm_StartFormAnchor (Action,Fol_FOLLOW_SECTION_ID);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_BUTTON_SUBMIT_Begin (Title,
(Gbl.Action.Act == Action) ? "BT_LINK FOLLOW_NUM_B" :
"BT_LINK FOLLOW_NUM",
@@ -624,7 +624,7 @@ static void Fol_ShowNumberOfFollowingOrFollowers (const struct UsrData *UsrDat,
{
/* Form to list users */
Frm_StartFormAnchor (Action,Fol_FOLLOW_SECTION_ID);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_BUTTON_SUBMIT_Begin (Title,
(Gbl.Action.Act == Action) ? The_ClassFormLinkOutBoxBold[Gbl.Prefs.Theme] :
The_ClassFormLinkOutBox [Gbl.Prefs.Theme],
@@ -845,7 +845,7 @@ static void Fol_ShowFollowedOrFollower (struct UsrData *UsrDat)
{
/* Put form to go to public profile */
Frm_StartForm (ActSeeOthPubPrf);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_DIV_Begin ("class=\"FOLLOW_USR_NAME\""); // Limited width
HTM_BUTTON_SUBMIT_Begin (Txt_Another_user_s_profile,"BT_LINK LT DAT",NULL);
Usr_WriteFirstNameBRSurnames (UsrDat);
@@ -902,7 +902,7 @@ static void Fol_WriteRowUsrToFollowOnRightColumn (struct UsrData *UsrDat)
{
/* Put form to go to public profile */
Frm_StartForm (ActSeeOthPubPrf);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_DIV_Begin ("class=\"CON_NAME_FOLLOW\""); // Limited width
HTM_BUTTON_SUBMIT_Begin (Txt_Another_user_s_profile,"BT_LINK CON_NAME_FOLLOW CON_CRS",NULL);
Usr_WriteFirstNameBRSurnames (UsrDat);
@@ -956,7 +956,7 @@ static void Fol_PutIconToFollow (struct UsrData *UsrDat)
/***** Form to unfollow *****/
Frm_StartForm (ActFolUsr);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_INPUT_IMAGE (Cfg_URL_ICON_PUBLIC,"user-plus.svg",
Txt_Follow,"FOLLOW_USR_ICO ICO_HIGHLIGHT ICO16x16");
Frm_EndForm ();
@@ -972,7 +972,7 @@ static void Fol_PutIconToUnfollow (struct UsrData *UsrDat)
/* Form to follow */
Frm_StartForm (ActUnfUsr);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_INPUT_IMAGE (Cfg_URL_ICON_PUBLIC,"user-check.svg",
Txt_Unfollow,"FOLLOW_USR_ICO ICO_HIGHLIGHT ICO16x16");
Frm_EndForm ();
@@ -1168,7 +1168,7 @@ static void Fol_GetFollowedFromSelectedUsrs (unsigned *NumFollowed,
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
if (Gbl.Usrs.Me.UsrDat.UsrCod != UsrDat.UsrCod) // Skip me
@@ -1217,7 +1217,7 @@ void Fol_FollowUsrs ()
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
if (Gbl.Usrs.Me.UsrDat.UsrCod != UsrDat.UsrCod) // Skip me
@@ -1264,7 +1264,7 @@ void Fol_UnfollowUsrs (void)
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
if (Gbl.Usrs.Me.UsrDat.UsrCod != UsrDat.UsrCod) // Skip me
@@ -1463,7 +1463,7 @@ void Fol_GetNotifFollower (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
{
SummaryStr[0] = '\0'; // Return nothing on error
- if ((*ContentStr = (char *) malloc (1)))
+ if ((*ContentStr = malloc (1)))
*ContentStr[0] = '\0';
}
diff --git a/swad_form.c b/swad_form.c
index 10ac2a6f..916dea8a 100644
--- a/swad_form.c
+++ b/swad_form.c
@@ -57,9 +57,7 @@ static void Frm_StartFormInternal (Act_Action_t NextAction,bool PutParameterLoca
void Frm_StartFormGoTo (Act_Action_t NextAction)
{
Gbl.Form.Num++; // Initialized to -1. The first time it is incremented, it will be equal to 0
- snprintf (Gbl.Form.Id,sizeof (Gbl.Form.Id),
- "form_%d",
- Gbl.Form.Num);
+ snprintf (Gbl.Form.Id,sizeof (Gbl.Form.Id),"form_%d",Gbl.Form.Num);
Frm_StartFormInternal (NextAction,false,Gbl.Form.Id,NULL,NULL); // Do not put now parameter location
}
@@ -81,9 +79,7 @@ void Frm_StartFormOnSubmit (Act_Action_t NextAction,const char *OnSubmit)
void Frm_StartFormAnchorOnSubmit (Act_Action_t NextAction,const char *Anchor,const char *OnSubmit)
{
Gbl.Form.Num++; // Initialized to -1. The first time it is incremented, it will be equal to 0
- snprintf (Gbl.Form.Id,sizeof (Gbl.Form.Id),
- "form_%d",
- Gbl.Form.Num);
+ snprintf (Gbl.Form.Id,sizeof (Gbl.Form.Id),"form_%d",Gbl.Form.Num);
Frm_StartFormInternal (NextAction,true,Gbl.Form.Id,Anchor,OnSubmit); // Do put now parameter location (if no open session)
}
@@ -95,8 +91,7 @@ void Frm_StartFormUnique (Act_Action_t NextAction)
void Frm_StartFormUniqueAnchor (Act_Action_t NextAction,const char *Anchor)
{
Gbl.Form.Num++; // Initialized to -1. The first time it is incremented, it will be equal to 0
- snprintf (Gbl.Form.UniqueId,sizeof (Gbl.Form.UniqueId),
- "form_%s_%d",
+ snprintf (Gbl.Form.UniqueId,sizeof (Gbl.Form.UniqueId),"form_%s_%d",
Gbl.UniqueNameEncrypted,Gbl.Form.Num);
Frm_StartFormInternal (NextAction,true,Gbl.Form.UniqueId,Anchor,NULL); // Do put now parameter location (if no open session)
}
@@ -104,8 +99,7 @@ void Frm_StartFormUniqueAnchor (Act_Action_t NextAction,const char *Anchor)
void Frm_StartFormUniqueAnchorOnSubmit (Act_Action_t NextAction,const char *Anchor,const char *OnSubmit)
{
Gbl.Form.Num++; // Initialized to -1. The first time it is incremented, it will be equal to 0
- snprintf (Gbl.Form.UniqueId,sizeof (Gbl.Form.UniqueId),
- "form_%s_%d",
+ snprintf (Gbl.Form.UniqueId,sizeof (Gbl.Form.UniqueId),"form_%s_%d",
Gbl.UniqueNameEncrypted,Gbl.Form.Num);
Frm_StartFormInternal (NextAction,true,Gbl.Form.UniqueId,Anchor,OnSubmit); // Do put now parameter location (if no open session)
}
@@ -236,8 +230,7 @@ void Frm_SetParamsForm (char ParamsStr[Frm_MAX_BYTES_PARAMS_STR + 1],Act_Action_
}
}
- snprintf (ParamsStr,Frm_MAX_BYTES_PARAMS_STR + 1,
- "%s%s%s",
+ snprintf (ParamsStr,Frm_MAX_BYTES_PARAMS_STR + 1,"%s%s%s",
ParamAction,ParamSession,ParamLocation);
}
@@ -263,8 +256,7 @@ void Frm_SetUniqueId (char UniqueId[Frm_MAX_BYTES_ID + 1])
So, Id uses:
- a name for this execution (Gbl.UniqueNameEncrypted)
- a number for each element in this execution (CountForThisExecution) *****/
- snprintf (UniqueId,Frm_MAX_BYTES_ID + 1,
- "id_%s_%u",
+ snprintf (UniqueId,Frm_MAX_BYTES_ID + 1,"id_%s_%u",
Gbl.UniqueNameEncrypted,
++CountForThisExecution);
}
diff --git a/swad_forum.c b/swad_forum.c
index e933c484..debcc647 100644
--- a/swad_forum.c
+++ b/swad_forum.c
@@ -720,8 +720,7 @@ static void For_GetThrSubject (long ThrCod,char Subject[Cns_MAX_BYTES_SUBJECT +
/***** Write the subject of the thread *****/
row = mysql_fetch_row (mysql_res);
- Str_Copy (Subject,row[0],
- Cns_MAX_BYTES_SUBJECT);
+ Str_Copy (Subject,row[0],Cns_MAX_BYTES_SUBJECT);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
@@ -1031,8 +1030,7 @@ static void For_ShowPostsOfAThread (struct For_Forums *Forums,
Ale_ShowAlert (AlertType,Message);
/***** Begin box *****/
- snprintf (FrameTitle,sizeof (FrameTitle),
- "%s: %s",
+ snprintf (FrameTitle,sizeof (FrameTitle),"%s: %s",
Txt_Thread,Thread.Subject);
Box_BoxBegin (NULL,FrameTitle,
For_PutIconNewPost,Forums,
@@ -1231,8 +1229,7 @@ static void For_ShowAForumPost (struct For_Forums *Forums,
if (Enabled)
/* Return this subject as last subject */
- Str_Copy (LastSubject,Subject,
- Cns_MAX_BYTES_SUBJECT);
+ Str_Copy (LastSubject,Subject,Cns_MAX_BYTES_SUBJECT);
HTM_TR_Begin (NULL);
@@ -1320,8 +1317,7 @@ static void For_ShowAForumPost (struct For_Forums *Forums,
HTM_TD_Begin ("class=\"MSG_TXT LT\"");
if (Enabled)
{
- Str_Copy (Content,OriginalContent,
- Cns_MAX_BYTES_LONG_TEXT);
+ Str_Copy (Content,OriginalContent,sizeof (Content) - 1);
Msg_WriteMsgContent (Content,Cns_MAX_BYTES_LONG_TEXT,true,false);
/***** Show image *****/
@@ -1376,12 +1372,10 @@ static void For_GetPstData (long PstCod,long *UsrCod,time_t *CreatTimeUTC,
*CreatTimeUTC = Dat_GetUNIXTimeFromStr (row[1]);
/***** Get subject (row[2]) *****/
- Str_Copy (Subject,row[2],
- Cns_MAX_BYTES_SUBJECT);
+ Str_Copy (Subject,row[2],Cns_MAX_BYTES_SUBJECT);
/***** Get location (row[3]) *****/
- Str_Copy (Content,row[3],
- Cns_MAX_BYTES_LONG_TEXT);
+ Str_Copy (Content,row[3],Cns_MAX_BYTES_LONG_TEXT);
/***** Get media (row[4]) *****/
Media->MedCod = Str_ConvertStrCodToLongCod (row[4]);
@@ -1416,20 +1410,18 @@ void For_GetSummaryAndContentForumPst (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1
row = mysql_fetch_row (mysql_res);
/***** Copy subject *****/
- Str_Copy (SummaryStr,row[0],
- Ntf_MAX_BYTES_SUMMARY);
+ Str_Copy (SummaryStr,row[0],Ntf_MAX_BYTES_SUMMARY);
/***** Copy content *****/
if (GetContent)
{
Length = strlen (row[1]);
- if ((*ContentStr = (char *) malloc (Length + 1)) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for notification content.");
+ if ((*ContentStr = malloc (Length + 1)) == NULL)
+ Lay_NotEnoughMemoryExit ();
if (Length)
- Str_Copy (*ContentStr,row[1],
- Length);
+ Str_Copy (*ContentStr,row[1],Length);
else
**ContentStr = '\0';
}
@@ -2179,20 +2171,18 @@ void For_SetForumName (const struct For_Forum *Forum,
For_MAX_BYTES_FORUM_NAME);
break;
case For_FORUM_GLOBAL_TCHS:
- snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1,
- "%s%s",
+ snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1,"%s%s",
UseHTMLEntities ? Txt_General :
Txt_General_NO_HTML[Language],
UseHTMLEntities ? Txt_only_teachers :
Txt_only_teachers_NO_HTML[Language]);
break;
case For_FORUM__SWAD__USRS:
- Str_Copy (ForumName,Cfg_PLATFORM_SHORT_NAME,
- For_MAX_BYTES_FORUM_NAME);
+ Str_Copy (ForumName,Cfg_PLATFORM_SHORT_NAME,For_MAX_BYTES_FORUM_NAME);
break;
case For_FORUM__SWAD__TCHS:
- snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1,
- "%s%s",Cfg_PLATFORM_SHORT_NAME,
+ snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1,"%s%s",
+ Cfg_PLATFORM_SHORT_NAME,
UseHTMLEntities ? Txt_only_teachers :
Txt_only_teachers_NO_HTML[Language]);
break;
@@ -2200,15 +2190,14 @@ void For_SetForumName (const struct For_Forum *Forum,
Hie.Ins.InsCod = Forum->Location;
if (!Ins_GetDataOfInstitutionByCod (&Hie.Ins))
Lay_ShowErrorAndExit ("Institution not found.");
- Str_Copy (ForumName,Hie.Ins.ShrtName,
- For_MAX_BYTES_FORUM_NAME);
+ Str_Copy (ForumName,Hie.Ins.ShrtName,For_MAX_BYTES_FORUM_NAME);
break;
case For_FORUM_INSTIT_TCHS:
Hie.Ins.InsCod = Forum->Location;
if (!Ins_GetDataOfInstitutionByCod (&Hie.Ins))
Lay_ShowErrorAndExit ("Institution not found.");
- snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1,
- "%s%s",Hie.Ins.ShrtName,
+ snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1,"%s%s",
+ Hie.Ins.ShrtName,
UseHTMLEntities ? Txt_only_teachers :
Txt_only_teachers_NO_HTML[Language]);
break;
@@ -2216,15 +2205,14 @@ void For_SetForumName (const struct For_Forum *Forum,
Hie.Ctr.CtrCod = Forum->Location;
if (!Ctr_GetDataOfCentreByCod (&Hie.Ctr))
Lay_ShowErrorAndExit ("Centre not found.");
- Str_Copy (ForumName,Hie.Ctr.ShrtName,
- For_MAX_BYTES_FORUM_NAME);
+ Str_Copy (ForumName,Hie.Ctr.ShrtName,For_MAX_BYTES_FORUM_NAME);
break;
case For_FORUM_CENTRE_TCHS:
Hie.Ctr.CtrCod = Forum->Location;
if (!Ctr_GetDataOfCentreByCod (&Hie.Ctr))
Lay_ShowErrorAndExit ("Centre not found.");
- snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1,
- "%s%s",Hie.Ctr.ShrtName,
+ snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1,"%s%s",
+ Hie.Ctr.ShrtName,
UseHTMLEntities ? Txt_only_teachers :
Txt_only_teachers_NO_HTML[Language]);
break;
@@ -2232,15 +2220,14 @@ void For_SetForumName (const struct For_Forum *Forum,
Hie.Deg.DegCod = Forum->Location;
if (!Deg_GetDataOfDegreeByCod (&Hie.Deg))
Lay_ShowErrorAndExit ("Degree not found.");
- Str_Copy (ForumName,Hie.Deg.ShrtName,
- For_MAX_BYTES_FORUM_NAME);
+ Str_Copy (ForumName,Hie.Deg.ShrtName,For_MAX_BYTES_FORUM_NAME);
break;
case For_FORUM_DEGREE_TCHS:
Hie.Deg.DegCod = Forum->Location;
if (!Deg_GetDataOfDegreeByCod (&Hie.Deg))
Lay_ShowErrorAndExit ("Degree not found.");
- snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1,
- "%s%s",Hie.Deg.ShrtName,
+ snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1,"%s%s",
+ Hie.Deg.ShrtName,
UseHTMLEntities ? Txt_only_teachers :
Txt_only_teachers_NO_HTML[Language]);
break;
@@ -2248,21 +2235,19 @@ void For_SetForumName (const struct For_Forum *Forum,
Hie.Crs.CrsCod = Forum->Location;
if (!Crs_GetDataOfCourseByCod (&Hie.Crs))
Lay_ShowErrorAndExit ("Course not found.");
- Str_Copy (ForumName,Hie.Crs.ShrtName,
- For_MAX_BYTES_FORUM_NAME);
+ Str_Copy (ForumName,Hie.Crs.ShrtName,For_MAX_BYTES_FORUM_NAME);
break;
case For_FORUM_COURSE_TCHS:
Hie.Crs.CrsCod = Forum->Location;
if (!Crs_GetDataOfCourseByCod (&Hie.Crs))
Lay_ShowErrorAndExit ("Course not found.");
- snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1,
- "%s%s",Hie.Crs.ShrtName,
+ snprintf (ForumName,For_MAX_BYTES_FORUM_NAME + 1,"%s%s",
+ Hie.Crs.ShrtName,
UseHTMLEntities ? Txt_only_teachers :
Txt_only_teachers_NO_HTML[Language]);
break;
default:
- Str_Copy (ForumName,Txt_Unknown_FORUM,
- For_MAX_BYTES_FORUM_NAME);
+ Str_Copy (ForumName,Txt_Unknown_FORUM,For_MAX_BYTES_FORUM_NAME);
}
}
@@ -2504,9 +2489,7 @@ static void For_ShowForumThreadsHighlightingOneThread (struct For_Forums *Forums
Ale_ShowAlert (AlertType,Message);
/***** Begin box for threads of this forum *****/
- snprintf (FrameTitle,sizeof (FrameTitle),
- "%s: %s",
- Txt_Forum,ForumName);
+ snprintf (FrameTitle,sizeof (FrameTitle),"%s: %s",Txt_Forum,ForumName);
Box_BoxBegin (NULL,FrameTitle,
For_PutIconNewThread,Forums,
Hlp_COMMUNICATION_Forums_threads,Box_NOT_CLOSABLE);
@@ -3520,12 +3503,9 @@ static void For_GetThreadData (struct For_Thread *Thr)
Thr->WriteTime[Dat_END_TIME ] = Dat_GetUNIXTimeFromStr (row[5]);
/***** Get the subject of this thread (row[6]) *****/
- Str_Copy (Thr->Subject,row[6],
- Cns_MAX_BYTES_SUBJECT);
+ Str_Copy (Thr->Subject,row[6],sizeof (Thr->Subject) - 1);
if (!Thr->Subject[0])
- snprintf (Thr->Subject,sizeof (Thr->Subject),
- "[%s]",
- Txt_no_subject);
+ snprintf (Thr->Subject,sizeof (Thr->Subject),"[%s]",Txt_no_subject);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
@@ -4260,7 +4240,7 @@ void For_CutThread (void)
if (Subject[0])
{
snprintf (Message,sizeof (Message),
- Txt_Thread_X_marked_to_be_moved,Subject);
+ Txt_Thread_X_marked_to_be_moved,Subject);
For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,Message);
}
else
@@ -4301,8 +4281,7 @@ void For_PasteThread (void)
if (Subject[0])
{
snprintf (Message,sizeof (Message),
- Txt_The_thread_X_is_already_in_this_forum,
- Subject);
+ Txt_The_thread_X_is_already_in_this_forum,Subject);
For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_WARNING,Message);
}
else
@@ -4320,8 +4299,7 @@ void For_PasteThread (void)
if (Subject[0])
{
snprintf (Message,sizeof (Message),
- Txt_Thread_X_moved_to_this_forum,
- Subject);
+ Txt_Thread_X_moved_to_this_forum,Subject);
For_ShowForumThreadsHighlightingOneThread (&Forums,Ale_SUCCESS,Message);
}
else
diff --git a/swad_game.c b/swad_game.c
index 63eb3c80..35a8a651 100644
--- a/swad_game.c
+++ b/swad_game.c
@@ -30,7 +30,6 @@
#include // For PATH_MAX
#include // For NULL
#include // For asprintf
-#include // For calloc
#include // For string functions
#include "swad_database.h"
@@ -919,7 +918,7 @@ void Gam_GetListGames (struct Gam_Games *Games,Gam_Order_t SelectedOrder)
Games->Num = (unsigned) NumRows;
/***** Create list of games *****/
- if ((Games->Lst = (struct Gam_GameSelected *) malloc (NumRows * sizeof (struct Gam_GameSelected))) == NULL)
+ if ((Games->Lst = malloc (NumRows * sizeof (*Games->Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the games codes *****/
@@ -963,7 +962,7 @@ void Gam_GetListSelectedGamCods (struct Gam_Games *Games)
/***** Allocate memory for list of games selected *****/
MaxSizeListGamCodsSelected = Games->Num * (Cns_MAX_DECIMAL_DIGITS_LONG + 1);
- if ((Games->GamCodsSelected = (char *) malloc (MaxSizeListGamCodsSelected + 1)) == NULL)
+ if ((Games->GamCodsSelected = malloc (MaxSizeListGamCodsSelected + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get parameter multiple with list of games selected *****/
@@ -1062,8 +1061,7 @@ void Gam_GetDataOfGameByCod (struct Gam_Game *Game)
Game->Visibility = TstVis_GetVisibilityFromStr (row[5]);
/* Get the title of the game (row[6]) */
- Str_Copy (Game->Title,row[6],
- Gam_MAX_BYTES_TITLE);
+ Str_Copy (Game->Title,row[6],sizeof (Game->Title) - 1);
/* Get number of questions */
Game->NumQsts = Gam_GetNumQstsGame (Game->GamCod);
@@ -1148,8 +1146,7 @@ static void Gam_GetGameTxtFromDB (long GamCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
{
/* Get info text */
row = mysql_fetch_row (mysql_res);
- Str_Copy (Txt,row[0],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Txt,row[0],Cns_MAX_BYTES_TEXT);
}
else
Txt[0] = '\0';
@@ -2106,9 +2103,7 @@ static void Gam_ListOneOrMoreQuestionsForEdition (struct Gam_Games *Games,
/* Get question index (row[0]) */
QstInd = Str_ConvertStrToUnsigned (row[0]);
- snprintf (StrQstInd,sizeof (StrQstInd),
- "%u",
- QstInd);
+ snprintf (StrQstInd,sizeof (StrQstInd),"%u",QstInd);
/* Get question code (row[1]) */
Question.QstCod = Str_ConvertStrCodToLongCod (row[1]);
@@ -2309,7 +2304,7 @@ static void Gam_AllocateListSelectedQuestions (struct Gam_Games *Games)
{
if (!Games->ListQuestions)
{
- if ((Games->ListQuestions = (char *) malloc (Gam_MAX_BYTES_LIST_SELECTED_QUESTIONS + 1)) == NULL)
+ if ((Games->ListQuestions = malloc (Gam_MAX_BYTES_LIST_SELECTED_QUESTIONS + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
Games->ListQuestions[0] = '\0';
}
diff --git a/swad_global.c b/swad_global.c
index a804c7c4..fbdb5b25 100644
--- a/swad_global.c
+++ b/swad_global.c
@@ -144,14 +144,10 @@ void Gbl_InitializeGlobals (void)
Gbl.Prefs.Menu = Mnu_MENU_DEFAULT; // Default menu
Gbl.Prefs.Theme = The_THEME_DEFAULT; // Default theme
Gbl.Prefs.IconSet = Ico_ICON_SET_DEFAULT; // Default icon set
- snprintf (Gbl.Prefs.URLTheme,sizeof (Gbl.Prefs.URLTheme),
- "%s/%s",
- Cfg_URL_ICON_THEMES_PUBLIC,
- The_ThemeId[Gbl.Prefs.Theme]);
- snprintf (Gbl.Prefs.URLIconSet,sizeof (Gbl.Prefs.URLIconSet),
- "%s/%s",
- Cfg_URL_ICON_SETS_PUBLIC,
- Ico_IconSetId[Gbl.Prefs.IconSet]);
+ snprintf (Gbl.Prefs.URLTheme,sizeof (Gbl.Prefs.URLTheme),"%s/%s",
+ Cfg_URL_ICON_THEMES_PUBLIC,The_ThemeId[Gbl.Prefs.Theme]);
+ snprintf (Gbl.Prefs.URLIconSet,sizeof (Gbl.Prefs.URLIconSet),"%s/%s",
+ Cfg_URL_ICON_SETS_PUBLIC,Ico_IconSetId[Gbl.Prefs.IconSet]);
Gbl.Session.NumSessions = 0;
Gbl.Session.IsOpen = false;
diff --git a/swad_group.c b/swad_group.c
index 0812cd8d..ea72993c 100644
--- a/swad_group.c
+++ b/swad_group.c
@@ -502,7 +502,7 @@ void Grp_PutParamsCodGrps (void)
Gbl.Crs.Grps.LstGrpsSel.NumGrps)
{
MaxLengthGrpCods = Gbl.Crs.Grps.LstGrpsSel.NumGrps * (Cns_MAX_DECIMAL_DIGITS_LONG + 1) - 1;
- if ((GrpCods = (char *) malloc (MaxLengthGrpCods + 1)) == NULL)
+ if ((GrpCods = malloc (MaxLengthGrpCods + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
GrpCods[0] = '\0';
@@ -513,8 +513,7 @@ void Grp_PutParamsCodGrps (void)
/* Append group code to list */
if (NumGrpSel)
Str_Concat (GrpCods,Par_SEPARATOR_PARAM_MULTIPLE,MaxLengthGrpCods);
- snprintf (GrpCod,sizeof (GrpCod),
- "%ld",
+ snprintf (GrpCod,sizeof (GrpCod),"%ld",
Gbl.Crs.Grps.LstGrpsSel.GrpCods[NumGrpSel]);
Str_Concat (GrpCods,GrpCod,MaxLengthGrpCods);
}
@@ -553,7 +552,8 @@ void Grp_GetParCodsSeveralGrpsToShowUsrs (void)
if (LstGrpsIBelong.NumGrps)
{
/* Allocate space for list of selected groups */
- if ((Gbl.Crs.Grps.LstGrpsSel.GrpCods = (long *) calloc (LstGrpsIBelong.NumGrps,sizeof (long))) == NULL)
+ if ((Gbl.Crs.Grps.LstGrpsSel.GrpCods = calloc (LstGrpsIBelong.NumGrps,
+ sizeof (*Gbl.Crs.Grps.LstGrpsSel.GrpCods))) == NULL)
Lay_NotEnoughMemoryExit ();
/* Fill list of selected groups with list of groups I belong to */
@@ -591,7 +591,7 @@ void Grp_GetParCodsSeveralGrps (void)
if (Gbl.Crs.Grps.NumGrps) // If course has groups
{
/***** Allocate memory for the list of group codes selected *****/
- if ((ParamLstCodGrps = (char *) malloc (MaxSizeLstGrpCods + 1)) == NULL)
+ if ((ParamLstCodGrps = malloc (MaxSizeLstGrpCods + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get parameter with list of groups to list *****/
@@ -609,7 +609,8 @@ void Grp_GetParCodsSeveralGrps (void)
if (Gbl.Crs.Grps.LstGrpsSel.NumGrps) // If I have selected groups...
{
/***** Create a list of groups selected from LstCodGrps *****/
- if ((Gbl.Crs.Grps.LstGrpsSel.GrpCods = (long *) calloc (Gbl.Crs.Grps.LstGrpsSel.NumGrps,sizeof (long))) == NULL)
+ if ((Gbl.Crs.Grps.LstGrpsSel.GrpCods = calloc (Gbl.Crs.Grps.LstGrpsSel.NumGrps,
+ sizeof (*Gbl.Crs.Grps.LstGrpsSel.GrpCods))) == NULL)
Lay_NotEnoughMemoryExit ();
for (Ptr = ParamLstCodGrps, NumGrp = 0;
*Ptr;
@@ -1064,7 +1065,8 @@ static void Grp_ConstructorListGrpAlreadySelec (struct ListGrpsAlreadySelec **Al
unsigned NumGrpTyp;
/***** Allocate memory to a list of booleanos that indica if already se ha selected a group of cada type *****/
- if ((*AlreadyExistsGroupOfType = (struct ListGrpsAlreadySelec *) calloc (Gbl.Crs.Grps.GrpTypes.Num,sizeof (struct ListGrpsAlreadySelec))) == NULL)
+ if ((*AlreadyExistsGroupOfType = calloc (Gbl.Crs.Grps.GrpTypes.Num,
+ sizeof (**AlreadyExistsGroupOfType))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Initialize the list *****/
@@ -1384,9 +1386,7 @@ static void Grp_ListGroupTypesForEdition (void)
HTM_TD_End ();
HTM_TD_Begin ("class=\"LM\"");
- snprintf (Id,sizeof (Id),
- "open_time_%u",
- UniqueId);
+ snprintf (Id,sizeof (Id),"open_time_%u",UniqueId);
Dat_WriteFormClientLocalDateTimeFromTimeUTC (Id,
"Open",
Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].OpenTimeUTC,
@@ -2064,9 +2064,7 @@ static bool Grp_ListGrpsForChangeMySelection (struct GroupType *GrpTyp,
else
HTM_TD_Begin ("class=\"LM\"");
- snprintf (StrGrpCod,sizeof (StrGrpCod),
- "GrpCod%ld",
- GrpTyp->GrpTypCod);
+ snprintf (StrGrpCod,sizeof (StrGrpCod),"GrpCod%ld",GrpTyp->GrpTypCod);
if (Gbl.Usrs.Me.Role.Logged == Rol_STD && // If I am a student
!GrpTyp->MultipleEnrolment && // ...and the enrolment is single
GrpTyp->NumGrps > 1) // ...and there are more than one group
@@ -2191,9 +2189,7 @@ static void Grp_ListGrpsToAddOrRemUsrs (struct GroupType *GrpTyp,long UsrCod)
/* Put checkbox to select the group */
// Always checkbox, not radio, because the role in the form may be teacher,
// so if he/she is registered as teacher, he/she can belong to several groups
- snprintf (StrGrpCod,sizeof (StrGrpCod),
- "GrpCod%ld",
- GrpTyp->GrpTypCod);
+ snprintf (StrGrpCod,sizeof (StrGrpCod),"GrpCod%ld",GrpTyp->GrpTypCod);
HTM_INPUT_CHECKBOX (StrGrpCod,HTM_DONT_SUBMIT_ON_CHANGE,
"id=\"Grp%ld\" value=\"%ld\"%s",
Grp->GrpCod,Grp->GrpCod,
@@ -2808,7 +2804,8 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
if (Gbl.Crs.Grps.GrpTypes.Num)
{
/***** Create a list of group types *****/
- if ((Gbl.Crs.Grps.GrpTypes.LstGrpTypes = (struct GroupType *) calloc (Gbl.Crs.Grps.GrpTypes.Num,sizeof (struct GroupType))) == NULL)
+ if ((Gbl.Crs.Grps.GrpTypes.LstGrpTypes = calloc (Gbl.Crs.Grps.GrpTypes.Num,
+ sizeof (*Gbl.Crs.Grps.GrpTypes.LstGrpTypes))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get group types *****/
@@ -2825,7 +2822,7 @@ void Grp_GetListGrpTypesInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
/* Get group type name (row[1]) */
Str_Copy (Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].GrpTypName,row[1],
- Grp_MAX_BYTES_GROUP_TYPE_NAME);
+ sizeof (Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].GrpTypName) - 1);
/* Is it mandatory to register in any groups of this type? (row[2]) */
Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].MandatoryEnrolment = (row[2][0] == 'Y');
@@ -2939,7 +2936,8 @@ void Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
GrpTyp->NumGrps = (unsigned) NumRows;
/***** Create list with groups of this type *****/
- if ((GrpTyp->LstGrps = (struct Group *) calloc (GrpTyp->NumGrps,sizeof (struct Group))) == NULL)
+ if ((GrpTyp->LstGrps = calloc (GrpTyp->NumGrps,
+ sizeof (*GrpTyp->LstGrps))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the groups of this type *****/
@@ -2957,8 +2955,7 @@ void Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
Lay_ShowErrorAndExit ("Wrong code of group.");
/* Get group name (row[1]) */
- Str_Copy (Grp->GrpName,row[1],
- Grp_MAX_BYTES_GROUP_NAME);
+ Str_Copy (Grp->GrpName,row[1],sizeof (Grp->GrpName) - 1);
/* Get room code (row[2]) */
Grp->Room.RooCod = Str_ConvertStrCodToLongCod (row[2]);
@@ -2966,7 +2963,7 @@ void Grp_GetListGrpTypesAndGrpsInThisCrs (Grp_WhichGroupTypes_t WhichGroupTypes)
/* Get room short name (row[3]) */
if (row[3]) // May be NULL because of LEFT JOIN
Str_Copy (Grp->Room.ShrtName,row[3],
- Roo_MAX_BYTES_SHRT_NAME);
+ sizeof (Grp->Room.ShrtName) - 1);
else // NULL
Grp->Room.ShrtName[0] = '\0';
@@ -3107,8 +3104,7 @@ static void Grp_GetDataOfGroupTypeByCod (struct GroupType *GrpTyp)
/***** Get some data of group type *****/
row = mysql_fetch_row (mysql_res);
- Str_Copy (GrpTyp->GrpTypName,row[0],
- Grp_MAX_BYTES_GROUP_TYPE_NAME);
+ Str_Copy (GrpTyp->GrpTypName,row[0],sizeof (GrpTyp->GrpTypName) - 1);
GrpTyp->MandatoryEnrolment = (row[1][0] == 'Y');
GrpTyp->MultipleEnrolment = (row[2][0] == 'Y');
GrpTyp->MustBeOpened = (row[3][0] == 'Y');
@@ -3204,15 +3200,13 @@ void Grp_GetDataOfGroupByCod (struct GroupData *GrpDat)
Lay_ShowErrorAndExit ("Wrong code of course.");
/* Get the name of the group type (row[2]) */
- Str_Copy (GrpDat->GrpTypName,row[2],
- Grp_MAX_BYTES_GROUP_TYPE_NAME);
+ Str_Copy (GrpDat->GrpTypName,row[2],sizeof (GrpDat->GrpTypName) - 1);
/* Get whether a student may be in one or multiple groups (row[3]) */
GrpDat->MultipleEnrolment = (row[3][0] == 'Y');
/* Get the name of the group (row[4]) */
- Str_Copy (GrpDat->GrpName,row[4],
- Grp_MAX_BYTES_GROUP_NAME);
+ Str_Copy (GrpDat->GrpName,row[4],sizeof (GrpDat->GrpName) - 1);
/* Get the code of the course (row[5]) */
GrpDat->Room.RooCod = Str_ConvertStrCodToLongCod (row[5]);
@@ -3220,7 +3214,7 @@ void Grp_GetDataOfGroupByCod (struct GroupData *GrpDat)
/* Get the name of the room (row[6]) */
if (row[6]) // May be NULL because of LEFT JOIN
Str_Copy (GrpDat->Room.ShrtName,row[6],
- Roo_MAX_BYTES_SHRT_NAME);
+ sizeof (GrpDat->Room.ShrtName) - 1);
else // NULL
GrpDat->Room.ShrtName[0] = '\0';
@@ -3611,7 +3605,8 @@ static void Grp_GetLstCodGrpsUsrBelongs (long CrsCod,long GrpTypCod,
if (LstGrps->NumGrps)
{
/***** Create a list of groups the user belongs to *****/
- if ((LstGrps->GrpCods = (long *) calloc (LstGrps->NumGrps,sizeof (long))) == NULL)
+ if ((LstGrps->GrpCods = calloc (LstGrps->NumGrps,
+ sizeof (*LstGrps->GrpCods))) == NULL)
Lay_NotEnoughMemoryExit ();
for (NumGrp = 0;
NumGrp < LstGrps->NumGrps;
@@ -3657,7 +3652,8 @@ void Grp_GetLstCodGrpsWithFileZonesIBelong (struct ListCodGrps *LstGrps)
if (LstGrps->NumGrps)
{
/***** Create a list of groups I belong to *****/
- if ((LstGrps->GrpCods = (long *) calloc (LstGrps->NumGrps,sizeof (long))) == NULL)
+ if ((LstGrps->GrpCods = calloc (LstGrps->NumGrps,
+ sizeof (*LstGrps->GrpCods))) == NULL)
Lay_NotEnoughMemoryExit ();
for (NumGrp = 0;
NumGrp < LstGrps->NumGrps;
@@ -3726,10 +3722,8 @@ void Grp_GetNamesGrpsStdBelongsTo (long GrpTypCod,long UsrCod,char *GroupNames)
/* El group name in row[0] */
if (NumRow)
- Str_Concat (GroupNames,", ",
- MaxLength);
- Str_Concat (GroupNames,row[0],
- MaxLength);
+ Str_Concat (GroupNames,", ",MaxLength);
+ Str_Concat (GroupNames,row[0],MaxLength);
}
/***** Free structure that stores the query result *****/
@@ -3770,7 +3764,7 @@ void Grp_ReceiveFormNewGrpTyp (void)
{
AlertType = Ale_WARNING;
snprintf (AlertTxt,sizeof (AlertTxt),
- Txt_The_type_of_group_X_already_exists,
+ Txt_The_type_of_group_X_already_exists,
Gbl.Crs.Grps.GrpTyp.GrpTypName);
}
else // Add new group type to database
@@ -4144,8 +4138,7 @@ static void Grp_RemoveGroupTypeCompletely (void)
Gbl.Crs.Grps.GrpTyp.GrpTypCod);
/***** Create message to show the change made *****/
- snprintf (AlertTxt,sizeof (AlertTxt),
- Txt_Type_of_group_X_removed,
+ snprintf (AlertTxt,sizeof (AlertTxt),Txt_Type_of_group_X_removed,
Gbl.Crs.Grps.GrpTyp.GrpTypName);
/***** Show the form again *****/
@@ -4198,8 +4191,7 @@ static void Grp_RemoveGroupCompletely (void)
Gbl.Crs.Grps.GrpCod);
/***** Create message to show the change made *****/
- snprintf (AlertTxt,sizeof (AlertTxt),
- Txt_Group_X_removed,
+ snprintf (AlertTxt,sizeof (AlertTxt),Txt_Group_X_removed,
GrpDat.GrpName);
/***** Show the form again *****/
@@ -4231,8 +4223,7 @@ void Grp_OpenGroup (void)
Gbl.Crs.Grps.GrpCod);
/***** Create message to show the change made *****/
- snprintf (AlertTxt,sizeof (AlertTxt),
- Txt_The_group_X_is_now_open,
+ snprintf (AlertTxt,sizeof (AlertTxt),Txt_The_group_X_is_now_open,
GrpDat.GrpName);
/***** Show the form again *****/
@@ -4265,8 +4256,7 @@ void Grp_CloseGroup (void)
Gbl.Crs.Grps.GrpCod);
/***** Create message to show the change made *****/
- snprintf (AlertTxt,sizeof (AlertTxt),
- Txt_The_group_X_is_now_closed,
+ snprintf (AlertTxt,sizeof (AlertTxt),Txt_The_group_X_is_now_closed,
GrpDat.GrpName);
/***** Show the form again *****/
@@ -4300,7 +4290,7 @@ void Grp_EnableFileZonesGrp (void)
/***** Create message to show the change made *****/
snprintf (AlertTxt,sizeof (AlertTxt),
- Txt_File_zones_of_the_group_X_are_now_enabled,
+ Txt_File_zones_of_the_group_X_are_now_enabled,
GrpDat.GrpName);
/***** Show the form again *****/
@@ -4373,8 +4363,7 @@ void Grp_ChangeGroupType (void)
{
/* Create warning message */
AlertType = Ale_WARNING;
- snprintf (AlertTxt,sizeof (AlertTxt),
- Txt_The_group_X_already_exists,
+ snprintf (AlertTxt,sizeof (AlertTxt),Txt_The_group_X_already_exists,
GrpDat.GrpName);
}
else // Group is not in database
@@ -4662,9 +4651,7 @@ void Grp_ChangeMaxStdsGrp (void)
static void Grp_WriteMaxStds (char Str[Cns_MAX_DECIMAL_DIGITS_UINT + 1],unsigned MaxStudents)
{
if (MaxStudents <= Grp_MAX_STUDENTS_IN_A_GROUP)
- snprintf (Str,Cns_MAX_DECIMAL_DIGITS_UINT + 1,
- "%u",
- MaxStudents);
+ snprintf (Str,Cns_MAX_DECIMAL_DIGITS_UINT + 1,"%u",MaxStudents);
else
Str[0] = '\0';
}
@@ -4721,8 +4708,7 @@ void Grp_RenameGroupType (void)
{
AlertType = Ale_WARNING;
snprintf (AlertTxt,sizeof (AlertTxt),
- Txt_The_type_of_group_X_already_exists,
- NewNameGrpTyp);
+ Txt_The_type_of_group_X_already_exists,NewNameGrpTyp);
}
else
{
@@ -4757,7 +4743,7 @@ void Grp_RenameGroupType (void)
/***** Show the form again *****/
Str_Copy (Gbl.Crs.Grps.GrpTyp.GrpTypName,NewNameGrpTyp,
- Grp_MAX_BYTES_GROUP_TYPE_NAME);
+ sizeof (Gbl.Crs.Grps.GrpTyp.GrpTypName) - 1);
Grp_ReqEditGroupsInternal (AlertType,AlertTxt,
Ale_INFO,NULL);
}
@@ -4807,8 +4793,7 @@ void Grp_RenameGroup (void)
{
AlertType = Ale_WARNING;
snprintf (AlertTxt,sizeof (AlertTxt),
- Txt_The_group_X_already_exists,
- NewNameGrp);
+ Txt_The_group_X_already_exists,NewNameGrp);
}
else
{
@@ -4828,14 +4813,12 @@ void Grp_RenameGroup (void)
{
AlertType = Ale_INFO;
snprintf (AlertTxt,sizeof (AlertTxt),
- Txt_The_name_of_the_group_X_has_not_changed,
- NewNameGrp);
+ Txt_The_name_of_the_group_X_has_not_changed,NewNameGrp);
}
}
/***** Show the form again *****/
- Str_Copy (Gbl.Crs.Grps.GrpName,NewNameGrp,
- Grp_MAX_BYTES_GROUP_NAME);
+ Str_Copy (Gbl.Crs.Grps.GrpName,NewNameGrp,sizeof (Gbl.Crs.Grps.GrpName) - 1);
Grp_ReqEditGroupsInternal (Ale_INFO,NULL,
AlertType,AlertTxt);
}
@@ -4894,7 +4877,8 @@ void Grp_GetLstCodsGrpWanted (struct ListCodGrps *LstGrpsWanted)
unsigned NumGrpWanted;
/***** Allocate memory for the strings with group codes in each type *****/
- if ((LstStrCodGrps = (char **) calloc (Gbl.Crs.Grps.GrpTypes.Num,sizeof (char *))) == NULL)
+ if ((LstStrCodGrps = calloc (Gbl.Crs.Grps.GrpTypes.Num,
+ sizeof (*LstStrCodGrps))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get lists with the groups that I want in each type
@@ -4904,13 +4888,12 @@ void Grp_GetLstCodsGrpWanted (struct ListCodGrps *LstGrpsWanted)
NumGrpTyp++)
{
/***** Allocate memory for the list of group codes of this type *****/
- if ((LstStrCodGrps[NumGrpTyp] = (char *) malloc ((size_t) ((Cns_MAX_DECIMAL_DIGITS_LONG + 1) *
- Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps))) == NULL)
+ if ((LstStrCodGrps[NumGrpTyp] = malloc (Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps *
+ (Cns_MAX_DECIMAL_DIGITS_LONG + 1))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the multiple parameter code of group of this type *****/
- snprintf (Param,sizeof (Param),
- "GrpCod%ld",
+ snprintf (Param,sizeof (Param),"GrpCod%ld",
Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].GrpTypCod);
Par_GetParMultiToText (Param,LstStrCodGrps[NumGrpTyp],
((Cns_MAX_DECIMAL_DIGITS_LONG + 1) * Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].NumGrps) - 1);
@@ -4931,8 +4914,9 @@ void Grp_GetLstCodsGrpWanted (struct ListCodGrps *LstGrpsWanted)
with all the groups selected (of all the types) *****/
if (LstGrpsWanted->NumGrps)
{
- if ((LstGrpsWanted->GrpCods = (long *) calloc (LstGrpsWanted->NumGrps,sizeof (long))) == NULL)
- Lay_ShowErrorAndExit ("Not enoguh memory to store codes of groups in which a user wants to be enroled.");
+ if ((LstGrpsWanted->GrpCods = calloc (LstGrpsWanted->NumGrps,
+ sizeof (*LstGrpsWanted->GrpCods))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/***** Get the groups *****/
for (NumGrpTyp = 0, NumGrpWanted = 0;
diff --git a/swad_hierarchy.c b/swad_hierarchy.c
index cacd8ab1..23730b68 100644
--- a/swad_hierarchy.c
+++ b/swad_hierarchy.c
@@ -599,14 +599,11 @@ void Hie_InitHierarchy (void)
if (Gbl.Hierarchy.Level == Hie_Lvl_CRS) // Course selected
{
/***** Paths of course directories *****/
- snprintf (Gbl.Crs.PathPriv,sizeof (Gbl.Crs.PathPriv),
- "%s/%ld",
+ snprintf (Gbl.Crs.PathPriv,sizeof (Gbl.Crs.PathPriv),"%s/%ld",
Cfg_PATH_CRS_PRIVATE,Gbl.Hierarchy.Crs.CrsCod);
- snprintf (Gbl.Crs.PathRelPubl,sizeof (Gbl.Crs.PathRelPubl),
- "%s/%ld",
+ snprintf (Gbl.Crs.PathRelPubl,sizeof (Gbl.Crs.PathRelPubl),"%s/%ld",
Cfg_PATH_CRS_PUBLIC,Gbl.Hierarchy.Crs.CrsCod);
- snprintf (Gbl.Crs.PathURLPubl,sizeof (Gbl.Crs.PathURLPubl),
- "%s/%ld",
+ snprintf (Gbl.Crs.PathURLPubl,sizeof (Gbl.Crs.PathURLPubl),"%s/%ld",
Cfg_URL_CRS_PUBLIC,Gbl.Hierarchy.Crs.CrsCod);
/***** If any of the course directories does not exist, create it *****/
diff --git a/swad_holiday.c b/swad_holiday.c
index 68ce07fb..fcbc3d7f 100644
--- a/swad_holiday.c
+++ b/swad_holiday.c
@@ -366,9 +366,8 @@ void Hld_GetListHolidays (struct Hld_Holidays *Holidays)
if (Holidays->Num) // Holidays found...
{
/***** Create list of holidays *****/
- if ((Holidays->Lst = (struct Hld_Holiday *)
- calloc ((size_t) Holidays->Num,
- sizeof (struct Hld_Holiday))) == NULL)
+ if ((Holidays->Lst = calloc (Holidays->Num,
+ sizeof (*Holidays->Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the holidays *****/
@@ -390,7 +389,7 @@ void Hld_GetListHolidays (struct Hld_Holidays *Holidays)
/* Get the full name of the place (row[2]) */
Str_Copy (Hld->PlaceFullName,row[2],
- Plc_MAX_BYTES_PLACE_FULL_NAME);
+ sizeof (Hld->PlaceFullName) - 1);
/* Get type (row[3]) */
Hld->HldTyp = Hld_GetTypeOfHoliday (row[3]);
@@ -414,8 +413,7 @@ void Hld_GetListHolidays (struct Hld_Holidays *Holidays)
}
/* Get the name of the holiday/non school period (row[6]) */
- Str_Copy (Hld->Name,row[6],
- Hld_MAX_BYTES_HOLIDAY_NAME);
+ Str_Copy (Hld->Name,row[6],sizeof (Hld->Name) - 1);
}
}
@@ -487,8 +485,7 @@ static void Hld_GetDataOfHolidayByCod (struct Hld_Holiday *Hld)
Hld->PlcCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get the full name of the place (row[1]) */
- Str_Copy (Hld->PlaceFullName,row[1],
- Plc_MAX_BYTES_PLACE_FULL_NAME);
+ Str_Copy (Hld->PlaceFullName,row[1],sizeof (Hld->PlaceFullName) - 1);
/* Get type (row[2]) */
Hld->HldTyp = Hld_GetTypeOfHoliday (row[2]);
@@ -512,8 +509,7 @@ static void Hld_GetDataOfHolidayByCod (struct Hld_Holiday *Hld)
}
/* Get the name of the holiday/non school period (row[5]) */
- Str_Copy (Hld->Name,row[5],
- Hld_MAX_BYTES_HOLIDAY_NAME);
+ Str_Copy (Hld->Name,row[5],sizeof (Hld->Name) - 1);
}
/***** Free structure that stores the query result *****/
@@ -769,7 +765,7 @@ void Hld_ChangeHolidayPlace (void)
NewPlace.PlcCod,Hld_EditingHld->HldCod);
Hld_EditingHld->PlcCod = NewPlace.PlcCod;
Str_Copy (Hld_EditingHld->PlaceFullName,NewPlace.FullName,
- Plc_MAX_BYTES_PLACE_FULL_NAME);
+ sizeof (Hld_EditingHld->PlaceFullName) - 1);
/***** Write message to show the change made *****/
Ale_CreateAlert (Ale_SUCCESS,NULL,
@@ -938,7 +934,7 @@ void Hld_RenameHoliday (void)
"UPDATE holidays SET Name='%s' WHERE HldCod=%ld",
NewHldName,Hld_EditingHld->HldCod);
Str_Copy (Hld_EditingHld->Name,NewHldName,
- Hld_MAX_BYTES_HOLIDAY_NAME);
+ sizeof (Hld_EditingHld->Name) - 1);
/***** Write message to show the change made *****/
Ale_CreateAlert (Ale_SUCCESS,NULL,
@@ -1203,8 +1199,8 @@ static void Hld_EditingHolidayConstructor (void)
Lay_ShowErrorAndExit ("Error initializing holiday.");
/***** Allocate memory for holiday *****/
- if ((Hld_EditingHld = (struct Hld_Holiday *) malloc (sizeof (struct Hld_Holiday))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for holiday.");
+ if ((Hld_EditingHld = malloc (sizeof (*Hld_EditingHld))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/***** Reset place *****/
Hld_EditingHld->HldCod = -1L;
diff --git a/swad_icon.c b/swad_icon.c
index 0ea0fbdf..5b8817c9 100644
--- a/swad_icon.c
+++ b/swad_icon.c
@@ -91,11 +91,9 @@ const char *Ico_GetIcon (const char *IconWithoutExtension)
NumExt < Ico_NUM_ICON_EXTENSIONS;
NumExt++)
{
- snprintf (IconWithExtension,sizeof (IconWithExtension),
- "%s.%s",
+ snprintf (IconWithExtension,sizeof (IconWithExtension),"%s.%s",
IconWithoutExtension,Ico_IconExtensions[NumExt]);
- snprintf (PathIcon,sizeof (PathIcon),
- "%s/%s/%s",
+ snprintf (PathIcon,sizeof (PathIcon),"%s/%s/%s",
Cfg_PATH_ICON_SETS_PUBLIC,
Ico_IconSetId[Gbl.Prefs.IconSet],
IconWithExtension);
@@ -131,8 +129,7 @@ void Ico_PutIconsToSelectIconSet (void)
"PREF_OFF");
Frm_StartForm (ActChgIco);
Par_PutHiddenParamString (NULL,"IconSet",Ico_IconSetId[IconSet]);
- snprintf (Icon,sizeof (Icon),
- "%s/%s/cog.svg",
+ snprintf (Icon,sizeof (Icon),"%s/%s/cog.svg",
Cfg_ICON_FOLDER_SETS,
Ico_IconSetId[IconSet]);
Ico_PutSettingIconLink (Icon,Ico_IconSetNames[IconSet]);
@@ -162,8 +159,7 @@ void Ico_ChangeIconSet (void)
{
/***** Get param with icon set *****/
Gbl.Prefs.IconSet = Ico_GetParamIconSet ();
- snprintf (Gbl.Prefs.URLIconSet,sizeof (Gbl.Prefs.URLIconSet),
- "%s/%s",
+ snprintf (Gbl.Prefs.URLIconSet,sizeof (Gbl.Prefs.URLIconSet),"%s/%s",
Cfg_URL_ICON_SETS_PUBLIC,
Ico_IconSetId[Gbl.Prefs.IconSet]);
diff --git a/swad_info.c b/swad_info.c
index 0735b266..3496c75c 100644
--- a/swad_info.c
+++ b/swad_info.c
@@ -754,15 +754,13 @@ static bool Inf_CheckPage (long CrsCod,Inf_InfoType_t InfoType)
/***** Open file with web page *****/
/* 1. Check if index.html exists */
- snprintf (PathRelFileHTML,sizeof (PathRelFileHTML),
- "%s/index.html",
+ snprintf (PathRelFileHTML,sizeof (PathRelFileHTML),"%s/index.html",
PathRelDirHTML);
if (Fil_CheckIfPathExists (PathRelFileHTML)) // TODO: Check if not empty?
return true;
/* 2. If index.html does not exist, try index.htm */
- snprintf (PathRelFileHTML,sizeof (PathRelFileHTML),
- "%s/index.htm",
+ snprintf (PathRelFileHTML,sizeof (PathRelFileHTML),"%s/index.htm",
PathRelDirHTML);
if (Fil_CheckIfPathExists (PathRelFileHTML)) // TODO: Check if not empty?
return true;
@@ -789,13 +787,11 @@ static bool Inf_CheckAndShowPage (void)
/***** Open file with web page *****/
/* 1. Check if index.html exists */
- snprintf (PathRelFileHTML,sizeof (PathRelFileHTML),
- "%s/index.html",
+ snprintf (PathRelFileHTML,sizeof (PathRelFileHTML),"%s/index.html",
PathRelDirHTML);
if (Fil_CheckIfPathExists (PathRelFileHTML)) // TODO: Check if not empty?
{
- snprintf (URL,sizeof (URL),
- "%s/%ld/%s/index.html",
+ snprintf (URL,sizeof (URL),"%s/%ld/%s/index.html",
Cfg_URL_CRS_PUBLIC,Gbl.Hierarchy.Crs.CrsCod,
Inf_FileNamesForInfoType[Gbl.Crs.Info.Type]);
Inf_ShowPage (URL);
@@ -804,13 +800,11 @@ static bool Inf_CheckAndShowPage (void)
}
/* 2. If index.html does not exist, try index.htm */
- snprintf (PathRelFileHTML,sizeof (PathRelFileHTML),
- "%s/index.htm",
+ snprintf (PathRelFileHTML,sizeof (PathRelFileHTML),"%s/index.htm",
PathRelDirHTML);
if (Fil_CheckIfPathExists (PathRelFileHTML)) // TODO: Check if not empty?
{
- snprintf (URL,sizeof (URL),
- "%s/%ld/%s/index.htm",
+ snprintf (URL,sizeof (URL),"%s/%ld/%s/index.htm",
Cfg_URL_CRS_PUBLIC,Gbl.Hierarchy.Crs.CrsCod,
Inf_FileNamesForInfoType[Gbl.Crs.Info.Type]);
Inf_ShowPage (URL);
@@ -827,10 +821,8 @@ static bool Inf_CheckAndShowPage (void)
void Inf_BuildPathPage (long CrsCod,Inf_InfoType_t InfoType,char PathDir[PATH_MAX + 1])
{
- snprintf (PathDir,PATH_MAX + 1,
- "%s/%ld/%s",
- Cfg_PATH_CRS_PUBLIC,CrsCod,
- Inf_FileNamesForInfoType[InfoType]);
+ snprintf (PathDir,PATH_MAX + 1,"%s/%ld/%s",
+ Cfg_PATH_CRS_PUBLIC,CrsCod,Inf_FileNamesForInfoType[InfoType]);
}
/*****************************************************************************/
@@ -899,10 +891,8 @@ static bool Inf_CheckAndShowURL (void)
static void Inf_BuildPathURL (long CrsCod,Inf_InfoType_t InfoType,
char PathFile[PATH_MAX + 1])
{
- snprintf (PathFile,PATH_MAX + 1,
- "%s/%ld/%s.url",
- Cfg_PATH_CRS_PRIVATE,CrsCod,
- Inf_FileNamesForInfoType[InfoType]);
+ snprintf (PathFile,PATH_MAX + 1,"%s/%ld/%s.url",
+ Cfg_PATH_CRS_PRIVATE,CrsCod,Inf_FileNamesForInfoType[InfoType]);
}
/*****************************************************************************/
@@ -1669,13 +1659,11 @@ void Inf_GetInfoTxtFromDB (long CrsCod,Inf_InfoType_t InfoType,
/* Get text in HTML format (not rigorous) */
if (InfoTxtHTML)
- Str_Copy (InfoTxtHTML,row[0],
- Cns_MAX_BYTES_LONG_TEXT);
+ Str_Copy (InfoTxtHTML,row[0],Cns_MAX_BYTES_LONG_TEXT);
/* Get text in Markdown format */
if (InfoTxtMD)
- Str_Copy (InfoTxtMD,row[1],
- Cns_MAX_BYTES_LONG_TEXT);
+ Str_Copy (InfoTxtMD,row[1],Cns_MAX_BYTES_LONG_TEXT);
}
else
{
@@ -1843,11 +1831,9 @@ static bool Inf_CheckAndShowRichTxt (void)
/***** Store text into a temporary .md file in HTML output directory *****/
// TODO: change to another directory?
/* Create a unique name for the .md file */
- snprintf (PathFileMD,sizeof (PathFileMD),
- "%s/%s.md",
+ snprintf (PathFileMD,sizeof (PathFileMD),"%s/%s.md",
Cfg_PATH_OUT_PRIVATE,Gbl.UniqueNameEncrypted);
- snprintf (PathFileHTML,sizeof (PathFileHTML),
- "%s/%s.md.html", // Do not use only .html because that is the output temporary file
+ snprintf (PathFileHTML,sizeof (PathFileHTML),"%s/%s.md.html", // Do not use only .html because that is the output temporary file
Cfg_PATH_OUT_PRIVATE,Gbl.UniqueNameEncrypted);
/* Open Markdown file for writing */
@@ -1875,8 +1861,7 @@ static bool Inf_CheckAndShowRichTxt (void)
/* MathJax 3.0.1 */
#ifdef Cfg_MATHJAX_LOCAL
// Use the local copy of MathJax
- snprintf (MathJaxURL,sizeof (MathJaxURL),
- "=%s/mathjax/tex-chtml.js",
+ snprintf (MathJaxURL,sizeof (MathJaxURL),"=%s/mathjax/tex-chtml.js",
Cfg_URL_SWAD_PUBLIC);
#else
// Use the MathJax Content Delivery Network (CDN)
@@ -2052,8 +2037,7 @@ void Inf_RecAndChangePlainTxtInfo (void)
/***** Get text with course information from form *****/
Par_GetParameter (Par_PARAM_SINGLE,"Txt",Txt_HTMLFormat,
Cns_MAX_BYTES_LONG_TEXT,NULL);
- Str_Copy (Txt_MarkdownFormat,Txt_HTMLFormat,
- Cns_MAX_BYTES_LONG_TEXT);
+ Str_Copy (Txt_MarkdownFormat,Txt_HTMLFormat,sizeof (Txt_MarkdownFormat) - 1);
Str_ChangeFormat (Str_FROM_FORM,Str_TO_HTML,
Txt_HTMLFormat,Cns_MAX_BYTES_LONG_TEXT,true); // Store in HTML format (not rigorous)
Str_ChangeFormat (Str_FROM_FORM,Str_TO_MARKDOWN,
@@ -2092,8 +2076,7 @@ void Inf_RecAndChangeRichTxtInfo (void)
/***** Get text with course information from form *****/
Par_GetParameter (Par_PARAM_SINGLE,"Txt",Txt_HTMLFormat,
Cns_MAX_BYTES_LONG_TEXT,NULL);
- Str_Copy (Txt_MarkdownFormat,Txt_HTMLFormat,
- Cns_MAX_BYTES_LONG_TEXT);
+ Str_Copy (Txt_MarkdownFormat,Txt_HTMLFormat,sizeof (Txt_MarkdownFormat) - 1);
Str_ChangeFormat (Str_FROM_FORM,Str_TO_HTML,
Txt_HTMLFormat,Cns_MAX_BYTES_LONG_TEXT,true); // Store in HTML format (not rigorous)
Str_ChangeFormat (Str_FROM_FORM,Str_TO_MARKDOWN,
@@ -2231,8 +2214,7 @@ void Inf_ReceivePagInfo (void)
{
Fil_RemoveTree (PathRelDirHTML);
Fil_CreateDirIfNotExists (PathRelDirHTML);
- snprintf (PathRelFileHTML,sizeof (PathRelFileHTML),
- "%s/index.html",
+ snprintf (PathRelFileHTML,sizeof (PathRelFileHTML),"%s/index.html",
PathRelDirHTML);
if (Fil_EndReceptionOfFile (PathRelFileHTML,Param))
{
@@ -2246,8 +2228,7 @@ void Inf_ReceivePagInfo (void)
{
Fil_RemoveTree (PathRelDirHTML);
Fil_CreateDirIfNotExists (PathRelDirHTML);
- snprintf (PathRelFileZIP,sizeof (PathRelFileZIP),
- "%s/%s.zip",
+ snprintf (PathRelFileZIP,sizeof (PathRelFileZIP),"%s/%s.zip",
Gbl.Crs.PathPriv,
Inf_FileNamesForInfoType[Gbl.Crs.Info.Type]);
@@ -2256,15 +2237,13 @@ void Inf_ReceivePagInfo (void)
Ale_ShowAlert (Ale_SUCCESS,Txt_The_ZIP_file_has_been_received_successfully);
/* Uncompress ZIP */
- snprintf (StrUnzip,sizeof (StrUnzip),
- "unzip -qq -o %s -d %s",
+ snprintf (StrUnzip,sizeof (StrUnzip),"unzip -qq -o %s -d %s",
PathRelFileZIP,PathRelDirHTML);
if (system (StrUnzip) == 0)
{
/* Check if uploaded file is index.html or index.htm */
snprintf (PathRelFileHTML,sizeof (PathRelFileHTML),
- "%s/index.html",
- PathRelDirHTML);
+ "%s/index.html",PathRelDirHTML);
if (Fil_CheckIfPathExists (PathRelFileHTML))
{
Ale_ShowAlert (Ale_SUCCESS,Txt_The_ZIP_file_has_been_unzipped_successfully);
@@ -2274,8 +2253,7 @@ void Inf_ReceivePagInfo (void)
else
{
snprintf (PathRelFileHTML,sizeof (PathRelFileHTML),
- "%s/index.htm",
- PathRelDirHTML);
+ "%s/index.htm",PathRelDirHTML);
if (Fil_CheckIfPathExists (PathRelFileHTML))
{
Ale_ShowAlert (Ale_SUCCESS,Txt_The_ZIP_file_has_been_unzipped_successfully);
diff --git a/swad_institution.c b/swad_institution.c
index 2d89bc56..7891be0f 100644
--- a/swad_institution.c
+++ b/swad_institution.c
@@ -646,8 +646,8 @@ void Ins_GetBasicListOfInstitutions (long CtyCod)
Gbl.Hierarchy.Inss.Num = (unsigned) NumRows;
/***** Create list with institutions *****/
- if ((Gbl.Hierarchy.Inss.Lst = (struct Ins_Instit *)
- calloc (NumRows,sizeof (struct Ins_Instit))) == NULL)
+ if ((Gbl.Hierarchy.Inss.Lst = calloc (NumRows,
+ sizeof (*Gbl.Hierarchy.Inss.Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the institutions *****/
@@ -730,8 +730,8 @@ void Ins_GetFullListOfInstitutions (long CtyCod)
Gbl.Hierarchy.Inss.Num = (unsigned) NumRows;
/***** Create list with institutions *****/
- if ((Gbl.Hierarchy.Inss.Lst = (struct Ins_Instit *)
- calloc (NumRows,sizeof (struct Ins_Instit))) == NULL)
+ if ((Gbl.Hierarchy.Inss.Lst = calloc (NumRows,
+ sizeof (*Gbl.Hierarchy.Inss.Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the institutions *****/
@@ -849,16 +849,13 @@ static void Ins_GetDataOfInstitFromRow (struct Ins_Instit *Ins,MYSQL_ROW row)
Ins->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[3]);
/***** Get the short name of the institution (row[4]) *****/
- Str_Copy (Ins->ShrtName,row[4],
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ Str_Copy (Ins->ShrtName,row[4],sizeof (Ins->ShrtName) - 1);
/***** Get the full name of the institution (row[5]) *****/
- Str_Copy (Ins->FullName,row[5],
- Cns_HIERARCHY_MAX_BYTES_FULL_NAME);
+ Str_Copy (Ins->FullName,row[5],sizeof (Ins->FullName) - 1);
/***** Get the URL of the institution (row[6]) *****/
- Str_Copy (Ins->WWW,row[6],
- Cns_MAX_BYTES_WWW);
+ Str_Copy (Ins->WWW ,row[6],sizeof (Ins->WWW ) - 1);
}
/*****************************************************************************/
@@ -887,7 +884,7 @@ void Ins_GetShortNameOfInstitution (struct Ins_Instit *Ins)
if (Ins->InsCod == Gbl.Cache.InstitutionShrtName.InsCod)
{
Str_Copy (Ins->ShrtName,Gbl.Cache.InstitutionShrtName.ShrtName,
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ sizeof (Ins->ShrtName) - 1);
return;
}
@@ -904,7 +901,7 @@ void Ins_GetShortNameOfInstitution (struct Ins_Instit *Ins)
row = mysql_fetch_row (mysql_res);
Str_Copy (Gbl.Cache.InstitutionShrtName.ShrtName,row[0],
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ sizeof (Gbl.Cache.InstitutionShrtName.ShrtName) - 1);
}
else
Gbl.Cache.InstitutionShrtName.ShrtName[0] = '\0';
@@ -913,7 +910,7 @@ void Ins_GetShortNameOfInstitution (struct Ins_Instit *Ins)
DB_FreeMySQLResult (&mysql_res);
Str_Copy (Ins->ShrtName,Gbl.Cache.InstitutionShrtName.ShrtName,
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ sizeof (Ins->ShrtName) - 1);
}
/*****************************************************************************/
@@ -946,7 +943,7 @@ static void Ins_GetShrtNameAndCtyOfInstitution (struct Ins_Instit *Ins,
if (Ins->InsCod == Gbl.Cache.InstitutionShrtNameAndCty.InsCod)
{
Str_Copy (Ins->ShrtName,Gbl.Cache.InstitutionShrtNameAndCty.ShrtName,
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ sizeof (Ins->ShrtName) - 1);
Str_Copy (CtyName,Gbl.Cache.InstitutionShrtNameAndCty.CtyName,
Cns_HIERARCHY_MAX_BYTES_FULL_NAME);
return;
@@ -968,11 +965,11 @@ static void Ins_GetShrtNameAndCtyOfInstitution (struct Ins_Instit *Ins,
/* Get the short name of this institution (row[0]) */
Str_Copy (Gbl.Cache.InstitutionShrtNameAndCty.ShrtName,row[0],
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ sizeof (Gbl.Cache.InstitutionShrtNameAndCty.ShrtName) - 1);
/* Get the name of the country (row[1]) */
Str_Copy (Gbl.Cache.InstitutionShrtNameAndCty.CtyName,row[1],
- Cns_HIERARCHY_MAX_BYTES_FULL_NAME);
+ sizeof (Gbl.Cache.InstitutionShrtNameAndCty.CtyName) - 1);
}
else
{
@@ -984,7 +981,7 @@ static void Ins_GetShrtNameAndCtyOfInstitution (struct Ins_Instit *Ins,
DB_FreeMySQLResult (&mysql_res);
Str_Copy (Ins->ShrtName,Gbl.Cache.InstitutionShrtNameAndCty.ShrtName,
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ sizeof (Ins->ShrtName) - 1);
Str_Copy (CtyName,Gbl.Cache.InstitutionShrtNameAndCty.CtyName,
Cns_HIERARCHY_MAX_BYTES_FULL_NAME);
}
@@ -1176,8 +1173,7 @@ static void Ins_ListInstitutionsForEdition (void)
}
else
{
- Str_Copy (WWW,Ins->WWW,
- Cns_MAX_BYTES_WWW);
+ Str_Copy (WWW,Ins->WWW,sizeof (WWW) - 1);
HTM_DIV_Begin ("class=\"EXTERNAL_WWW_SHORT\"");
HTM_A_Begin ("href=\"%s\" target=\"_blank\" class=\"DAT\" title=\"%s\"",
Ins->WWW,Ins->WWW);
@@ -1393,11 +1389,10 @@ void Ins_RemoveInstitution (void)
Brw_RemoveInsFilesFromDB (Ins_EditingIns->InsCod);
/***** Remove directories of the institution *****/
- snprintf (PathIns,sizeof (PathIns),
- "%s/%02u/%u",
+ snprintf (PathIns,sizeof (PathIns),"%s/%02u/%u",
Cfg_PATH_INS_PUBLIC,
(unsigned) (Ins_EditingIns->InsCod % 100),
- (unsigned) Ins_EditingIns->InsCod);
+ (unsigned) Ins_EditingIns->InsCod);
Fil_RemoveTree (PathIns);
/***** Remove institution *****/
@@ -1508,8 +1503,7 @@ void Ins_RenameInstitution (struct Ins_Instit *Ins,Cns_ShrtOrFullName_t ShrtOrFu
CurrentInsName,NewInsName);
/* Change current institution name in order to display it properly */
- Str_Copy (CurrentInsName,NewInsName,
- MaxBytes);
+ Str_Copy (CurrentInsName,NewInsName,MaxBytes);
}
}
else // The same name
@@ -1581,8 +1575,7 @@ void Ins_ChangeInsWWW (void)
{
/***** Update database changing old WWW by new WWW *****/
Ins_UpdateInsWWWDB (Ins_EditingIns->InsCod,NewWWW);
- Str_Copy (Ins_EditingIns->WWW,NewWWW,
- Cns_MAX_BYTES_WWW);
+ Str_Copy (Ins_EditingIns->WWW,NewWWW,sizeof (Ins_EditingIns->WWW) - 1);
/***** Write message to show the change made
and put button to go to institution changed *****/
@@ -2178,8 +2171,8 @@ static void Ins_EditingInstitutionConstructor (void)
Lay_ShowErrorAndExit ("Error initializing institution.");
/***** Allocate memory for institution *****/
- if ((Ins_EditingIns = (struct Ins_Instit *) malloc (sizeof (struct Ins_Instit))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for institution.");
+ if ((Ins_EditingIns = malloc (sizeof (*Ins_EditingIns))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/***** Reset institution *****/
Ins_EditingIns->InsCod = -1L;
diff --git a/swad_institution_config.c b/swad_institution_config.c
index 046b20a7..e5e66342 100644
--- a/swad_institution_config.c
+++ b/swad_institution_config.c
@@ -663,8 +663,7 @@ void InsCfg_ChangeInsWWW (void)
{
/***** Update database changing old WWW by new WWW *****/
Ins_UpdateInsWWWDB (Gbl.Hierarchy.Ins.InsCod,NewWWW);
- Str_Copy (Gbl.Hierarchy.Ins.WWW,NewWWW,
- Cns_MAX_BYTES_WWW);
+ Str_Copy (Gbl.Hierarchy.Ins.WWW,NewWWW,sizeof (Gbl.Hierarchy.Ins.WWW) - 1);
/***** Write message to show the change made *****/
Ale_ShowAlert (Ale_SUCCESS,Txt_The_new_web_address_is_X,
diff --git a/swad_layout.c b/swad_layout.c
index 8e357069..ffbf04ee 100644
--- a/swad_layout.c
+++ b/swad_layout.c
@@ -909,7 +909,7 @@ static void Lay_WriteScriptParamsAJAX (void)
HTM_TxtF ("var RefreshParamNxtActOldPub = \"act=%ld\";\n"
"var RefreshParamUsr = \"OtherUsrCod=%s\";\n",
Act_GetActCod (ActRefOldTL_PubUsr),
- Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Gbl.Usrs.Other.UsrDat.EnUsrCod);
break;
/* Parameters related with match refreshing (for students) */
case ActJoiMch:
diff --git a/swad_link.c b/swad_link.c
index f50b3b09..f2b18d13 100644
--- a/swad_link.c
+++ b/swad_link.c
@@ -303,7 +303,7 @@ void Lnk_GetListLinks (void)
Gbl.Links.Num = (unsigned) NumRows;
/***** Create list with places *****/
- if ((Gbl.Links.Lst = (struct Link *) calloc (NumRows,sizeof (struct Link))) == NULL)
+ if ((Gbl.Links.Lst = calloc (NumRows,sizeof (*Gbl.Links.Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the links *****/
@@ -320,17 +320,11 @@ void Lnk_GetListLinks (void)
if ((Lnk->LnkCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of institutional link.");
- /* Get the short name of the link (row[1]) */
- Str_Copy (Lnk->ShrtName,row[1],
- Lnk_MAX_BYTES_LINK_SHRT_NAME);
-
- /* Get the full name of the link (row[2]) */
- Str_Copy (Lnk->FullName,row[2],
- Lnk_MAX_BYTES_LINK_FULL_NAME);
-
- /* Get the URL of the link (row[3]) */
- Str_Copy (Lnk->WWW,row[3],
- Cns_MAX_BYTES_WWW);
+ /* Get the short name (row[0]), the full name (row[1])
+ and de URL (row[2]) of the link */
+ Str_Copy (Lnk->ShrtName,row[1],sizeof (Lnk->ShrtName) - 1);
+ Str_Copy (Lnk->FullName,row[2],sizeof (Lnk->FullName) - 1);
+ Str_Copy (Lnk->WWW ,row[3],sizeof (Lnk->WWW ) - 1);
}
}
else
@@ -369,17 +363,11 @@ void Lnk_GetDataOfLinkByCod (struct Link *Lnk)
/* Get row */
row = mysql_fetch_row (mysql_res);
- /* Get the short name of the link (row[0]) */
- Str_Copy (Lnk->ShrtName,row[0],
- Lnk_MAX_BYTES_LINK_SHRT_NAME);
-
- /* Get the full name of the link (row[1]) */
- Str_Copy (Lnk->FullName,row[1],
- Lnk_MAX_BYTES_LINK_FULL_NAME);
-
- /* Get the URL of the link (row[2]) */
- Str_Copy (Lnk->WWW,row[2],
- Cns_MAX_BYTES_WWW);
+ /* Get the short name (row[0]), the full name (row[1])
+ and de URL (row[2]) of the link */
+ Str_Copy (Lnk->ShrtName,row[0],sizeof (Lnk->ShrtName) - 1);
+ Str_Copy (Lnk->FullName,row[1],sizeof (Lnk->FullName) - 1);
+ Str_Copy (Lnk->WWW ,row[2],sizeof (Lnk->WWW ) - 1);
}
/***** Free structure that stores the query result *****/
@@ -622,8 +610,7 @@ static void Lnk_RenameLink (Cns_ShrtOrFullName_t ShrtOrFullName)
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
/***** Update name *****/
- Str_Copy (CurrentLnkName,NewLnkName,
- MaxBytes);
+ Str_Copy (CurrentLnkName,NewLnkName,MaxBytes);
}
/*****************************************************************************/
@@ -692,8 +679,7 @@ void Lnk_ChangeLinkWWW (void)
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
/***** Update web *****/
- Str_Copy (Lnk_EditingLnk->WWW,NewWWW,
- Cns_MAX_BYTES_WWW);
+ Str_Copy (Lnk_EditingLnk->WWW,NewWWW,sizeof (Lnk_EditingLnk->WWW) - 1);
}
/*****************************************************************************/
@@ -870,8 +856,8 @@ static void Lnk_EditingLinkConstructor (void)
Lay_ShowErrorAndExit ("Error initializing link.");
/***** Allocate memory for link *****/
- if ((Lnk_EditingLnk = (struct Link *) malloc (sizeof (struct Link))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for link.");
+ if ((Lnk_EditingLnk = malloc (sizeof (*Lnk_EditingLnk))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/***** Reset link *****/
Lnk_EditingLnk->LnkCod = -1L;
diff --git a/swad_log.c b/swad_log.c
index 87d7eb81..253d26cd 100644
--- a/swad_log.c
+++ b/swad_log.c
@@ -132,10 +132,9 @@ void Log_LogAccess (const char *Comments)
if (Comments)
{
MaxLength = strlen (Comments) * Str_MAX_BYTES_PER_CHAR;
- if ((CommentsDB = (char *) malloc (MaxLength + 1)) != NULL)
+ if ((CommentsDB = malloc (MaxLength + 1)) != NULL)
{
- Str_Copy (CommentsDB,Comments,
- MaxLength);
+ Str_Copy (CommentsDB,Comments,MaxLength);
Str_ChangeFormat (Str_FROM_TEXT,Str_TO_TEXT,
CommentsDB,MaxLength,true); // Avoid SQL injection
DB_QueryINSERT ("can not log access (comments)",
diff --git a/swad_logo.c b/swad_logo.c
index a058e68c..50329571 100644
--- a/swad_logo.c
+++ b/swad_logo.c
@@ -106,12 +106,11 @@ void Lgo_DrawLogo (Hie_Lvl_Level_t Scope,long Cod,const char *AltText,
{
Folder = Cfg_FOLDER_DEG;
DegCod = Cod;
- snprintf (PathLogo,sizeof (PathLogo),
- "%s/%02u/%u/logo/%u.png",
+ snprintf (PathLogo,sizeof (PathLogo),"%s/%02u/%u/logo/%u.png",
Cfg_PATH_DEG_PUBLIC,
(unsigned) (DegCod % 100),
- (unsigned) DegCod,
- (unsigned) DegCod);
+ (unsigned) DegCod,
+ (unsigned) DegCod);
LogoFound = Fil_CheckIfPathExists (PathLogo);
if (LogoFound)
Cod = DegCod;
@@ -125,12 +124,11 @@ void Lgo_DrawLogo (Hie_Lvl_Level_t Scope,long Cod,const char *AltText,
CtrCod = Deg_GetCtrCodOfDegreeByCod (Cod);
else
CtrCod = Cod;
- snprintf (PathLogo,sizeof (PathLogo),
- "%s/%02u/%u/logo/%u.png",
+ snprintf (PathLogo,sizeof (PathLogo),"%s/%02u/%u/logo/%u.png",
Cfg_PATH_CTR_PUBLIC,
(unsigned) (CtrCod % 100),
- (unsigned) CtrCod,
- (unsigned) CtrCod);
+ (unsigned) CtrCod,
+ (unsigned) CtrCod);
LogoFound = Fil_CheckIfPathExists (PathLogo);
if (LogoFound)
Cod = CtrCod;
@@ -146,12 +144,11 @@ void Lgo_DrawLogo (Hie_Lvl_Level_t Scope,long Cod,const char *AltText,
InsCod = Ctr_GetInsCodOfCentreByCod (Cod);
else
InsCod = Cod;
- snprintf (PathLogo,sizeof (PathLogo),
- "%s/%02u/%u/logo/%u.png",
+ snprintf (PathLogo,sizeof (PathLogo),"%s/%02u/%u/logo/%u.png",
Cfg_PATH_INS_PUBLIC,
(unsigned) (InsCod % 100),
- (unsigned) InsCod,
- (unsigned) InsCod);
+ (unsigned) InsCod,
+ (unsigned) InsCod);
LogoFound = Fil_CheckIfPathExists (PathLogo);
if (LogoFound)
Cod = InsCod;
@@ -233,12 +230,11 @@ void Lgo_PutIconToChangeLogo (Hie_Lvl_Level_t Scope)
}
/***** Check if logo exists *****/
- snprintf (PathLogo,sizeof (PathLogo),
- "%s/%s/%02u/%u/logo/%u.png",
+ snprintf (PathLogo,sizeof (PathLogo),"%s/%s/%02u/%u/logo/%u.png",
Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (Cod % 100),
- (unsigned) Cod,
- (unsigned) Cod);
+ (unsigned) Cod,
+ (unsigned) Cod);
LogoExists = Fil_CheckIfPathExists (PathLogo);
/***** Link for changing / uploading the logo *****/
@@ -291,12 +287,11 @@ void Lgo_RequestLogo (Hie_Lvl_Level_t Scope)
}
/***** Check if logo exists *****/
- snprintf (PathLogo,sizeof (PathLogo),
- "%s/%s/%02u/%u/logo/%u.png",
+ snprintf (PathLogo,sizeof (PathLogo),"%s/%s/%02u/%u/logo/%u.png",
Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (Cod % 100),
- (unsigned) Cod,
- (unsigned) Cod);
+ (unsigned) Cod,
+ (unsigned) Cod);
if (!Fil_CheckIfPathExists (PathLogo))
FunctionToDrawContextualIcons = NULL;
@@ -393,26 +388,18 @@ void Lgo_ReceiveLogo (Hie_Lvl_Level_t Scope)
}
/***** Creates directories if not exist *****/
- snprintf (Path,sizeof (Path),
- "%s/%s",
- Cfg_PATH_SWAD_PUBLIC,Folder);
+ snprintf (Path,sizeof (Path),"%s/%s",Cfg_PATH_SWAD_PUBLIC,Folder);
Fil_CreateDirIfNotExists (Path);
- snprintf (Path,sizeof (Path),
- "%s/%s/%02u",
- Cfg_PATH_SWAD_PUBLIC,Folder,
+ snprintf (Path,sizeof (Path),"%s/%s/%02u",Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (Cod % 100));
Fil_CreateDirIfNotExists (Path);
- snprintf (Path,sizeof (Path),
- "%s/%s/%02u/%u",
- Cfg_PATH_SWAD_PUBLIC,Folder,
+ snprintf (Path,sizeof (Path),"%s/%s/%02u/%u",Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (Cod % 100),
- (unsigned) Cod);
+ (unsigned) Cod);
Fil_CreateDirIfNotExists (Path);
- snprintf (Path,sizeof (Path),
- "%s/%s/%02u/%u/logo",
- Cfg_PATH_SWAD_PUBLIC,Folder,
+ snprintf (Path,sizeof (Path),"%s/%s/%02u/%u/logo",Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (Cod % 100),
- (unsigned) Cod);
+ (unsigned) Cod);
Fil_CreateDirIfNotExists (Path);
/***** Copy in disk the file received from stdin (really from Gbl.F.Tmp) *****/
@@ -432,12 +419,11 @@ void Lgo_ReceiveLogo (Hie_Lvl_Level_t Scope)
else
{
/* End the reception of logo in a temporary file */
- snprintf (FileNameLogo,sizeof (FileNameLogo),
- "%s/%s/%02u/%u/logo/%u.png",
+ snprintf (FileNameLogo,sizeof (FileNameLogo),"%s/%s/%02u/%u/logo/%u.png",
Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (Cod % 100),
- (unsigned) Cod,
- (unsigned) Cod);
+ (unsigned) Cod,
+ (unsigned) Cod);
if (!Fil_EndReceptionOfFile (FileNameLogo,Param))
Ale_ShowAlert (Ale_ERROR,"Error copying file.");
}
@@ -473,11 +459,10 @@ void Lgo_RemoveLogo (Hie_Lvl_Level_t Scope)
}
/***** Remove logo *****/
- snprintf (FileNameLogo,sizeof (FileNameLogo),
- "%s/%s/%02u/%u/logo/%u.png",
+ snprintf (FileNameLogo,sizeof (FileNameLogo),"%s/%s/%02u/%u/logo/%u.png",
Cfg_PATH_SWAD_PUBLIC,Folder,
(unsigned) (Cod % 100),
- (unsigned) Cod,
- (unsigned) Cod);
+ (unsigned) Cod,
+ (unsigned) Cod);
Fil_RemoveTree (FileNameLogo);
}
diff --git a/swad_mail.c b/swad_mail.c
index d18db8c3..71322159 100644
--- a/swad_mail.c
+++ b/swad_mail.c
@@ -301,7 +301,7 @@ static void Mai_GetListMailDomainsAllowedForNotif (void)
Gbl.Mails.Num = (unsigned) NumRows;
/***** Create list with places *****/
- if ((Gbl.Mails.Lst = (struct Mail *) calloc (NumRows,sizeof (struct Mail))) == NULL)
+ if ((Gbl.Mails.Lst = calloc (NumRows,sizeof (*Gbl.Mails.Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the mail domains *****/
@@ -318,13 +318,9 @@ static void Mai_GetListMailDomainsAllowedForNotif (void)
if ((Mai->MaiCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of mail domain.");
- /* Get the mail domain (row[1]) */
- Str_Copy (Mai->Domain,row[1],
- Cns_MAX_BYTES_EMAIL_ADDRESS);
-
- /* Get the mail domain info (row[2]) */
- Str_Copy (Mai->Info,row[2],
- Mai_MAX_BYTES_MAIL_INFO);
+ /* Get the mail domain (row[1]) and the mail domain info (row[2]) */
+ Str_Copy (Mai->Domain,row[1],sizeof (Mai->Domain) - 1);
+ Str_Copy (Mai->Info ,row[2],sizeof (Mai->Info ) - 1);
/* Get number of users (row[3]) */
if (sscanf (row[3],"%u",&(Mai->NumUsrs)) != 1)
@@ -374,8 +370,7 @@ static void Mai_GetMailDomain (const char *Email,char MailDomain[Cns_MAX_BYTES_E
{
Ptr++; // Skip '@'
if (strchr (Ptr,(int) '@') == NULL) // No more '@' found
- Str_Copy (MailDomain,Ptr,
- Cns_MAX_BYTES_EMAIL_ADDRESS);
+ Str_Copy (MailDomain,Ptr,Cns_MAX_BYTES_EMAIL_ADDRESS);
}
}
@@ -442,13 +437,9 @@ void Mai_GetDataOfMailDomainByCod (struct Mail *Mai)
/* Get row */
row = mysql_fetch_row (mysql_res);
- /* Get the short name of the mail (row[0]) */
- Str_Copy (Mai->Domain,row[0],
- Cns_MAX_BYTES_EMAIL_ADDRESS);
-
- /* Get the full name of the mail (row[1]) */
- Str_Copy (Mai->Info,row[1],
- Mai_MAX_BYTES_MAIL_INFO);
+ /* Get the short & full name of the mail (row[0], row[1]) */
+ Str_Copy (Mai->Domain,row[0],sizeof (Mai->Domain) - 1);
+ Str_Copy (Mai->Info ,row[1],sizeof (Mai->Info ) - 1);
}
/***** Free structure that stores the query result *****/
@@ -691,8 +682,7 @@ static void Mai_RenameMailDomain (Cns_ShrtOrFullName_t ShrtOrFullName)
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
/***** Update name *****/
- Str_Copy (CurrentMaiName,NewMaiName,
- MaxBytes);
+ Str_Copy (CurrentMaiName,NewMaiName,MaxBytes);
}
/*****************************************************************************/
@@ -944,7 +934,7 @@ static void Mai_ListEmails (__attribute__((unused)) void *Args)
while (*Ptr)
{
/* Get next user */
- Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
@@ -966,14 +956,12 @@ static void Mai_ListEmails (__attribute__((unused)) void *Args)
LengthStrAddr ++;
if (LengthStrAddr > Mai_MAX_BYTES_STR_ADDR)
Lay_ShowErrorAndExit ("The space allocated to store email addresses is full.");
- Str_Concat (StrAddresses,",",
- Mai_MAX_BYTES_STR_ADDR);
+ Str_Concat (StrAddresses,",",sizeof (StrAddresses) - 1);
}
LengthStrAddr += strlen (UsrDat.Email);
if (LengthStrAddr > Mai_MAX_BYTES_STR_ADDR)
Lay_ShowErrorAndExit ("The space allocated to store email addresses is full.");
- Str_Concat (StrAddresses,UsrDat.Email,
- Mai_MAX_BYTES_STR_ADDR);
+ Str_Concat (StrAddresses,UsrDat.Email,sizeof (StrAddresses) - 1);
HTM_A_Begin ("href=\"mailto:%s?subject=%s\"",
UsrDat.Email,Gbl.Hierarchy.Crs.FullName);
HTM_Txt (UsrDat.Email);
@@ -1099,8 +1087,7 @@ bool Mai_GetEmailFromUsrCod (struct UsrData *UsrDat)
{
/* Get email */
row = mysql_fetch_row (mysql_res);
- Str_Copy (UsrDat->Email,row[0],
- Cns_MAX_BYTES_EMAIL_ADDRESS);
+ Str_Copy (UsrDat->Email,row[0],sizeof (UsrDat->Email) - 1);
UsrDat->EmailConfirmed = (row[1][0] == 'Y');
Found = true;
}
@@ -1169,9 +1156,7 @@ void Mai_ShowFormChangeMyEmail (bool IMustFillInEmail,bool IShouldConfirmEmail)
HTM_SECTION_Begin (Mai_EMAIL_SECTION_ID);
/***** Begin box *****/
- snprintf (StrRecordWidth,sizeof (StrRecordWidth),
- "%upx",
- Rec_RECORD_WIDTH);
+ snprintf (StrRecordWidth,sizeof (StrRecordWidth),"%upx",Rec_RECORD_WIDTH);
Box_BoxBegin (StrRecordWidth,Txt_Email,
Acc_PutLinkToRemoveMyAccount,NULL,
Hlp_PROFILE_Account,Box_NOT_CLOSABLE);
@@ -1202,9 +1187,7 @@ void Mai_ShowFormChangeOtherUsrEmail (void)
HTM_SECTION_Begin (Mai_EMAIL_SECTION_ID);
/***** Begin box *****/
- snprintf (StrRecordWidth,sizeof (StrRecordWidth),
- "%upx",
- Rec_RECORD_WIDTH);
+ snprintf (StrRecordWidth,sizeof (StrRecordWidth),"%upx",Rec_RECORD_WIDTH);
Box_BoxBegin (StrRecordWidth,Txt_Email,
NULL,NULL,
Hlp_PROFILE_Account,Box_NOT_CLOSABLE);
@@ -1359,7 +1342,7 @@ static void Mai_ShowFormChangeUsrEmail (bool ItsMe,
break;
}
Frm_StartFormAnchor (NextAction,Mai_EMAIL_SECTION_ID);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
}
Par_PutHiddenParamString (NULL,"NewEmail",row[0]);
Btn_PutConfirmButtonInline ((ItsMe && NumEmail == 1) ? Txt_Confirm_email :
@@ -1405,7 +1388,7 @@ static void Mai_ShowFormChangeUsrEmail (bool ItsMe,
break;
}
Frm_StartFormAnchor (NextAction,Mai_EMAIL_SECTION_ID);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
}
HTM_INPUT_EMAIL ("NewEmail",Cns_MAX_CHARS_EMAIL_ADDRESS,Gbl.Usrs.Me.UsrDat.Email,
"id=\"NewEmail\" size=\"18\"");
@@ -1431,7 +1414,7 @@ static void Mai_PutParamsRemoveOtherEmail (void *Email)
{
if (Email)
{
- Usr_PutParamUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
Par_PutHiddenParamString (NULL,"Email",Email);
}
}
@@ -1792,8 +1775,7 @@ void Mai_ConfirmEmail (void)
UsrCod = Str_ConvertStrCodToLongCod (row[0]);
/* Get user's email */
- Str_Copy (Email,row[1],
- Cns_MAX_BYTES_EMAIL_ADDRESS);
+ Str_Copy (Email,row[1],sizeof (Email) - 1);
KeyIsCorrect = true;
}
@@ -1861,8 +1843,7 @@ void Mai_ConfirmEmail (void)
void Mai_CreateFileNameMail (char FileNameMail[PATH_MAX + 1],FILE **FileMail)
{
- snprintf (FileNameMail,PATH_MAX + 1,
- "%s/%s_mail.txt",
+ snprintf (FileNameMail,PATH_MAX + 1,"%s/%s_mail.txt",
Cfg_PATH_OUT_PRIVATE,Gbl.UniqueNameEncrypted);
if ((*FileMail = fopen (FileNameMail,"wb")) == NULL)
Lay_ShowErrorAndExit ("Can not open file to send email.");
@@ -1879,7 +1860,7 @@ void Mai_WriteWelcomeNoteEMail (FILE *FileMail,struct UsrData *UsrDat)
fprintf (FileMail,"%s %s:\n",
Txt_Dear_NO_HTML[UsrDat->Sex][UsrDat->Prefs.Language],
- UsrDat->FirstName[0] ? UsrDat->FirstName :
+ UsrDat->FrstName[0] ? UsrDat->FrstName :
Txt_user_NO_HTML[UsrDat->Sex][UsrDat->Prefs.Language]);
}
@@ -1958,8 +1939,8 @@ static void Mai_EditingMailDomainConstructor (void)
Lay_ShowErrorAndExit ("Error initializing mail domain.");
/***** Allocate memory for mail domain *****/
- if ((Mai_EditingMai = (struct Mail *) malloc (sizeof (struct Mail))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for mail domain.");
+ if ((Mai_EditingMai = malloc (sizeof (*Mai_EditingMai))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/***** Reset place *****/
Mai_EditingMai->MaiCod = -1L;
diff --git a/swad_mark.c b/swad_mark.c
index 889f3430..9f71a449 100644
--- a/swad_mark.c
+++ b/swad_mark.c
@@ -130,9 +130,7 @@ void Mrk_GetAndWriteNumRowsHeaderAndFooter (void)
Brw_PutImplicitParamsFileBrowser (&Gbl.FileBrowser.FilFolLnk);
HTM_LABEL_Begin (NULL);
HTM_TxtF (" %s: ",Txt_TABLE_Header);
- snprintf (StrHeadOrFoot,sizeof (StrHeadOrFoot),
- "%u",
- Marks.Header);
+ snprintf (StrHeadOrFoot,sizeof (StrHeadOrFoot),"%u",Marks.Header);
HTM_INPUT_TEXT (Mrk_HeadOrFootStr[Brw_HEADER],Cns_MAX_DECIMAL_DIGITS_UINT,StrHeadOrFoot,
HTM_SUBMIT_ON_CHANGE,
"size=\"1\" class=\"LST_EDIT_ROWS COLOR%u\"",
@@ -150,9 +148,7 @@ void Mrk_GetAndWriteNumRowsHeaderAndFooter (void)
Brw_PutImplicitParamsFileBrowser (&Gbl.FileBrowser.FilFolLnk);
HTM_LABEL_Begin (NULL);
HTM_TxtF (" %s: ",Txt_TABLE_Footer);
- snprintf (StrHeadOrFoot,sizeof (StrHeadOrFoot),
- "%u",
- Marks.Footer);
+ snprintf (StrHeadOrFoot,sizeof (StrHeadOrFoot),"%u",Marks.Footer);
HTM_INPUT_TEXT (Mrk_HeadOrFootStr[Brw_FOOTER],Cns_MAX_DECIMAL_DIGITS_UINT,StrHeadOrFoot,
HTM_SUBMIT_ON_CHANGE,
"size=\"1\" class=\"LST_EDIT_ROWS COLOR%u\"",
@@ -599,8 +595,7 @@ void Mrk_ShowMyMarks (void)
/***** Get the path of the file of marks *****/
Brw_SetFullPathInTree ();
- snprintf (PathPrivate,sizeof (PathPrivate),
- "%s/%s",
+ snprintf (PathPrivate,sizeof (PathPrivate),"%s/%s",
Gbl.FileBrowser.Priv.PathAboveRootFolder,
Gbl.FileBrowser.FilFolLnk.Full);
@@ -646,8 +641,7 @@ void Mrk_ShowMyMarks (void)
Fil_CreateDirIfNotExists (Cfg_PATH_MARK_PRIVATE);
/* Create a new temporary file *****/
- snprintf (FileNameUsrMarks,sizeof (FileNameUsrMarks),
- "%s/%s.html",
+ snprintf (FileNameUsrMarks,sizeof (FileNameUsrMarks),"%s/%s.html",
Cfg_PATH_MARK_PRIVATE,Gbl.UniqueNameEncrypted);
if ((FileUsrMarks = fopen (FileNameUsrMarks,"wb")) == NULL)
Lay_ShowErrorAndExit ("Can not open file for my marks.");
@@ -752,12 +746,11 @@ void Mrk_GetNotifMyMarks (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
/* Path (row[2]) */
Str_Copy (FullPathInTreeFromDBMarksTable,row[2],
- PATH_MAX);
+ sizeof (FullPathInTreeFromDBMarksTable) - 1);
Str_SplitFullPathIntoPathAndFileName (FullPathInTreeFromDBMarksTable,
PathUntilFileName,
FileName);
- Str_Copy (SummaryStr,FileName,
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (SummaryStr,FileName,Cns_MAX_BYTES_TEXT);
if (GetContent)
{
@@ -772,13 +765,11 @@ void Mrk_GetNotifMyMarks (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
if (UsrDat.IDs.Num)
{
if (GrpCod > 0)
- snprintf (PathMarks,sizeof (PathMarks),
- "%s/%ld/grp/%ld/%s",
+ snprintf (PathMarks,sizeof (PathMarks),"%s/%ld/grp/%ld/%s",
Cfg_PATH_CRS_PRIVATE,CrsCod,GrpCod,
FullPathInTreeFromDBMarksTable);
else
- snprintf (PathMarks,sizeof (PathMarks),
- "%s/%ld/%s",
+ snprintf (PathMarks,sizeof (PathMarks),"%s/%ld/%s",
Cfg_PATH_CRS_PRIVATE,CrsCod,
FullPathInTreeFromDBMarksTable);
@@ -787,8 +778,7 @@ void Mrk_GetNotifMyMarks (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
Fil_CreateDirIfNotExists (Cfg_PATH_MARK_PRIVATE);
/* Create a new temporary file *****/
- snprintf (FileNameUsrMarks,sizeof (FileNameUsrMarks),
- "%s/%s.html",
+ snprintf (FileNameUsrMarks,sizeof (FileNameUsrMarks),"%s/%s.html",
Cfg_PATH_MARK_PRIVATE,Gbl.UniqueNameEncrypted);
if ((FileUsrMarks = fopen (FileNameUsrMarks,"wb")))
{
@@ -799,11 +789,10 @@ void Mrk_GetNotifMyMarks (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
fclose (FileUsrMarks);
Length = 9 + SizeOfMyMarks + 3;
- if ((*ContentStr = (char *) malloc (Length + 1)))
+ if ((*ContentStr = malloc (Length + 1)))
{
/* 9 starting chars */
- Str_Copy (*ContentStr,"",
- 3);
+ Str_Copy (Ptr,"]]>",3);
}
}
else
diff --git a/swad_match.c b/swad_match.c
index c401a30e..282741a8 100644
--- a/swad_match.c
+++ b/swad_match.c
@@ -29,7 +29,6 @@
#include // For PATH_MAX
#include // For NULL
#include // For asprintf
-#include // For calloc
#include // For string functions
#include "swad_database.h"
@@ -1022,8 +1021,7 @@ static void Mch_GetMatchDataFromRow (MYSQL_RES *mysql_res,
/* Get the title of the match (row[5]) */
if (row[5])
- Str_Copy (Match->Title,row[5],
- Mch_MAX_BYTES_TITLE);
+ Str_Copy (Match->Title,row[5],sizeof (Match->Title) - 1);
else
Match->Title[0] = '\0';
@@ -1878,15 +1876,12 @@ static void Mch_ReorderAnswer (long MchCod,unsigned QstInd,
if ((LongNum = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong answer index.");
AnsInd = (unsigned) LongNum;
- snprintf (StrOneAnswer,sizeof (StrOneAnswer),
- "%u",AnsInd);
+ snprintf (StrOneAnswer,sizeof (StrOneAnswer),"%u",AnsInd);
/* Concatenate answer index to list of answers */
if (NumAns)
- Str_Concat (StrAnswersOneQst,",",
- Tst_MAX_BYTES_ANSWERS_ONE_QST);
- Str_Concat (StrAnswersOneQst,StrOneAnswer,
- Tst_MAX_BYTES_ANSWERS_ONE_QST);
+ Str_Concat (StrAnswersOneQst,",",sizeof (StrAnswersOneQst) - 1);
+ Str_Concat (StrAnswersOneQst,StrOneAnswer,sizeof (StrAnswersOneQst) - 1);
}
/***** Free structure that stores the query result *****/
@@ -1922,8 +1917,7 @@ void Mch_GetIndexes (long MchCod,unsigned QstInd,
row = mysql_fetch_row (mysql_res);
/* Get indexes (row[0]) */
- Str_Copy (StrIndexesOneQst,row[0],
- Tst_MAX_BYTES_INDEXES_ONE_QST);
+ Str_Copy (StrIndexesOneQst,row[0],sizeof (StrIndexesOneQst) - 1);
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
@@ -4283,14 +4277,15 @@ void Mch_GetMatchQuestionsFromDB (struct MchPrn_Print *Print)
/* Get indexes for this question (row[2]) */
Str_Copy (Print->PrintedQuestions[NumQst].StrIndexes,row[2],
- Tst_MAX_BYTES_INDEXES_ONE_QST);
+ sizeof (Print->PrintedQuestions[NumQst].StrIndexes) - 1);
/* Get answers selected by user for this question */
Mch_GetQstAnsFromDB (Print->MchCod,Print->UsrCod,QstInd,&UsrAnswer);
if (UsrAnswer.AnsInd >= 0) // UsrAnswer.AnsInd >= 0 ==> answer selected
{
- snprintf (Print->PrintedQuestions[NumQst].StrAnswers,Tst_MAX_BYTES_ANSWERS_ONE_QST + 1,
- "%d",UsrAnswer.AnsInd);
+ snprintf (Print->PrintedQuestions[NumQst].StrAnswers,
+ sizeof (Print->PrintedQuestions[NumQst].StrAnswers),
+ "%d",UsrAnswer.AnsInd);
Print->NumQsts.NotBlank++;
}
else // UsrAnswer.AnsInd < 0 ==> no answer selected
diff --git a/swad_match_result.c b/swad_match_result.c
index e2e85e8a..73a749b0 100644
--- a/swad_match_result.c
+++ b/swad_match_result.c
@@ -29,7 +29,6 @@
#include // For PATH_MAX
#include // For NULL
#include // For asprintf
-#include // For calloc
#include // For string functions
#include "swad_action.h"
@@ -308,7 +307,7 @@ static void MchRes_ListAllMchResultsInSelectedGames (struct Gam_Games *Games)
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,Gbl.Usrs.Other.UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Other.UsrDat);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS))
@@ -735,7 +734,7 @@ static void MchRes_BuildGamesSelectedCommas (struct Gam_Games *Games,
/***** Allocate memory for subquery of games selected *****/
MaxLength = (size_t) Games->NumSelected * (Cns_MAX_DECIMAL_DIGITS_LONG + 1);
- if ((*GamesSelectedCommas = (char *) malloc (MaxLength + 1)) == NULL)
+ if ((*GamesSelectedCommas = malloc (MaxLength + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Build subquery with list of selected games *****/
@@ -1018,7 +1017,7 @@ static void MchRes_ShowMchResults (struct Gam_Games *Games,
case Usr_OTHER:
Frm_StartForm (ActSeeOneMchResOth);
Mch_PutParamsEdit (Games);
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
break;
}
Ico_PutIconLink ("tasks.svg",Txt_Result);
@@ -1233,8 +1232,8 @@ void MchRes_ShowOneMchResult (void)
HTM_TxtF (" %s",UsrDat->Surname1);
if (UsrDat->Surname2[0])
HTM_TxtF (" %s",UsrDat->Surname2);
- if (UsrDat->FirstName[0])
- HTM_TxtF (", %s",UsrDat->FirstName);
+ if (UsrDat->FrstName[0])
+ HTM_TxtF (", %s",UsrDat->FrstName);
HTM_BR ();
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (UsrDat,PhotoURL);
Pho_ShowUsrPhoto (UsrDat,ShowPhoto ? PhotoURL :
diff --git a/swad_media.c b/swad_media.c
index e4878ffa..59895970 100644
--- a/swad_media.c
+++ b/swad_media.c
@@ -292,8 +292,7 @@ void Med_GetMediaDataByCod (struct Med_Media *Media)
Med_STATUS_NONE;
/***** Copy media name (row[1]) to struct *****/
- Str_Copy (Media->Name,row[1],
- Med_BYTES_NAME);
+ Str_Copy (Media->Name,row[1],sizeof (Media->Name) - 1);
/***** Copy media URL (row[2]) to struct *****/
// Media->URL can be empty or filled with previous value
@@ -306,10 +305,9 @@ void Med_GetMediaDataByCod (struct Med_Media *Media)
if (Length > Cns_MAX_BYTES_WWW)
Length = Cns_MAX_BYTES_WWW;
- if ((Media->URL = (char *) malloc (Length + 1)) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for media URL.");
- Str_Copy (Media->URL,row[2],
- Length);
+ if ((Media->URL = malloc (Length + 1)) == NULL)
+ Lay_NotEnoughMemoryExit ();
+ Str_Copy (Media->URL,row[2],Length);
}
/***** Copy media title (row[3]) to struct *****/
@@ -323,10 +321,9 @@ void Med_GetMediaDataByCod (struct Med_Media *Media)
if (Length > Med_MAX_BYTES_TITLE)
Length = Med_MAX_BYTES_TITLE;
- if ((Media->Title = (char *) malloc (Length + 1)) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for media title.");
- Str_Copy (Media->Title,row[3],
- Length);
+ if ((Media->Title = malloc (Length + 1)) == NULL)
+ Lay_NotEnoughMemoryExit ();
+ Str_Copy (Media->Title,row[3],Length);
}
}
else
@@ -340,7 +337,7 @@ void Med_GetMediaDataByCod (struct Med_Media *Media)
/********* Draw input fields to upload an image/video inside a form **********/
/*****************************************************************************/
-void Med_PutMediaUploader (int NumMediaInForm,const char *ClassInput)
+void Med_PutMediaUploader (int NumMedia,const char *ClassInput)
{
extern const char *Hlp_Multimedia;
extern const char *Txt_Multimedia;
@@ -380,7 +377,7 @@ void Med_PutMediaUploader (int NumMediaInForm,const char *ClassInput)
};
/***** Set names of parameters depending on number of media in form *****/
- Med_SetParamNames (&ParamUploadMedia,NumMediaInForm);
+ Med_SetParamNames (&ParamUploadMedia,NumMedia);
/***** Create unique id for this media uploader *****/
Frm_SetUniqueId (Id);
@@ -507,11 +504,11 @@ static void Med_PutHiddenFormTypeMediaUploader (const char UniqueId[Frm_MAX_BYTE
/******************** Get media (image/video) from form **********************/
/*****************************************************************************/
// Media constructor must be called before calling this function
-// If NumMediaInForm < 0, params have no suffix
-// If NumMediaInForm >= 0, the number is a suffix of the params
+// If NumMedia < 0, params have no suffix
+// If NumMedia >= 0, the number is a suffix of the params
-void Med_GetMediaFromForm (long CrsCod,long QstCod,int NumMediaInForm,struct Med_Media *Media,
- void (*GetMediaFromDB) (long CrsCod,long QstCod,int NumMediaInForm,struct Med_Media *Media),
+void Med_GetMediaFromForm (long CrsCod,long QstCod,int NumMedia,struct Med_Media *Media,
+ void (*GetMediaFromDB) (long CrsCod,long QstCod,int NumMedia,struct Med_Media *Media),
const char *SectionForAlerts)
{
extern const char *Txt_Error_sending_or_processing_image_video;
@@ -520,7 +517,7 @@ void Med_GetMediaFromForm (long CrsCod,long QstCod,int NumMediaInForm,struct Med
Med_FormType_t FormType;
/***** Set names of parameters depending on number of media in form *****/
- Med_SetParamNames (&ParamUploadMedia,NumMediaInForm);
+ Med_SetParamNames (&ParamUploadMedia,NumMedia);
/***** Get action and initialize media (image/video)
(except title, that will be get after the media file) *****/
@@ -584,7 +581,7 @@ void Med_GetMediaFromForm (long CrsCod,long QstCod,int NumMediaInForm,struct Med
/***** Get media name *****/
if (GetMediaFromDB != NULL)
- GetMediaFromDB (CrsCod,QstCod,NumMediaInForm,Media);
+ GetMediaFromDB (CrsCod,QstCod,NumMedia,Media);
break;
default: // Unknown action
Media->Action = Med_ACTION_NO_MEDIA;
@@ -595,41 +592,26 @@ void Med_GetMediaFromForm (long CrsCod,long QstCod,int NumMediaInForm,struct Med
/*****************************************************************************/
/********* Set parameters names depending on number of media in form *********/
/*****************************************************************************/
-// If NumMediaInForm < 0, params have no suffix
-// If NumMediaInForm >= 0, the number is a suffix of the params
+// If NumMedia < 0, params have no suffix
+// If NumMedia >= 0, the number is a suffix of the params
-void Med_SetParamNames (struct ParamUploadMedia *ParamUploadMedia,int NumMediaInForm)
+void Med_SetParamNames (struct ParamUploadMedia *ParamUpl,int NumMedia)
{
- if (NumMediaInForm < 0) // One unique media in form ==> no suffix needed
+ if (NumMedia < 0) // One unique media in form ==> no suffix needed
{
- Str_Copy (ParamUploadMedia->Action ,"MedAct",
- Med_MAX_BYTES_PARAM_UPLOAD_MEDIA);
- Str_Copy (ParamUploadMedia->FormType,"MedFrm",
- Med_MAX_BYTES_PARAM_UPLOAD_MEDIA);
- Str_Copy (ParamUploadMedia->File ,"MedFil",
- Med_MAX_BYTES_PARAM_UPLOAD_MEDIA);
- Str_Copy (ParamUploadMedia->Title ,"MedTit",
- Med_MAX_BYTES_PARAM_UPLOAD_MEDIA);
- Str_Copy (ParamUploadMedia->URL ,"MedURL",
- Med_MAX_BYTES_PARAM_UPLOAD_MEDIA);
+ Str_Copy (ParamUpl->Action ,"MedAct",sizeof (ParamUpl->Action ) - 1);
+ Str_Copy (ParamUpl->FormType,"MedFrm",sizeof (ParamUpl->FormType) - 1);
+ Str_Copy (ParamUpl->File ,"MedFil",sizeof (ParamUpl->File ) - 1);
+ Str_Copy (ParamUpl->Title ,"MedTit",sizeof (ParamUpl->Title ) - 1);
+ Str_Copy (ParamUpl->URL ,"MedURL",sizeof (ParamUpl->URL ) - 1);
}
else // Several video/images in form ==> add suffix
{
- snprintf (ParamUploadMedia->Action ,sizeof (ParamUploadMedia->Action),
- "MedAct%u",
- NumMediaInForm);
- snprintf (ParamUploadMedia->FormType,sizeof (ParamUploadMedia->Action),
- "MedFrm%u",
- NumMediaInForm);
- snprintf (ParamUploadMedia->File ,sizeof (ParamUploadMedia->File),
- "MedFil%u",
- NumMediaInForm);
- snprintf (ParamUploadMedia->Title ,sizeof (ParamUploadMedia->Title),
- "MedTit%u",
- NumMediaInForm);
- snprintf (ParamUploadMedia->URL ,sizeof (ParamUploadMedia->URL),
- "MedURL%u",
- NumMediaInForm);
+ snprintf (ParamUpl->Action ,sizeof (ParamUpl->Action),"MedAct%u",NumMedia);
+ snprintf (ParamUpl->FormType,sizeof (ParamUpl->Action),"MedFrm%u",NumMedia);
+ snprintf (ParamUpl->File ,sizeof (ParamUpl->File ),"MedFil%u",NumMedia);
+ snprintf (ParamUpl->Title ,sizeof (ParamUpl->Title ),"MedTit%u",NumMedia);
+ snprintf (ParamUpl->URL ,sizeof (ParamUpl->URL ),"MedURL%u",NumMedia);
}
}
@@ -677,10 +659,9 @@ static void Usr_GetURLFromForm (const char *ParamName,struct Med_Media *Media)
/* Overwrite current URL (empty or coming from database)
with the URL coming from the form */
Med_FreeMediaURL (Media);
- if ((Media->URL = (char *) malloc (Length + 1)) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for media URL.");
- Str_Copy (Media->URL,URL,
- Length);
+ if ((Media->URL = malloc (Length + 1)) == NULL)
+ Lay_NotEnoughMemoryExit ();
+ Str_Copy (Media->URL,URL,Length);
}
}
@@ -702,10 +683,9 @@ static void Usr_GetTitleFromForm (const char *ParamName,struct Med_Media *Media)
/* Overwrite current title (empty or coming from database)
with the title coming from the form */
Med_FreeMediaTitle (Media);
- if ((Media->Title = (char *) malloc (Length + 1)) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for media title.");
- Str_Copy (Media->Title,Title,
- Length);
+ if ((Media->Title = malloc (Length + 1)) == NULL)
+ Lay_NotEnoughMemoryExit ();
+ Str_Copy (Media->Title,Title,Length);
}
}
@@ -762,8 +742,7 @@ static void Med_GetAndProcessFileFromForm (const char *ParamFile,
/***** End the reception of original not processed media
(it may be very big) into a temporary file *****/
Media->Status = Med_STATUS_NONE;
- snprintf (PathFileOrg,sizeof (PathFileOrg),
- "%s/%s_original.%s",
+ snprintf (PathFileOrg,sizeof (PathFileOrg),"%s/%s_original.%s",
Cfg_PATH_MEDIA_TMP_PRIVATE,Media->Name,PtrExtension);
if (Fil_EndReceptionOfFile (PathFileOrg,Param)) // Success
@@ -813,13 +792,12 @@ static bool Med_DetectIfAnimated (struct Med_Media *Media,
int NumFrames = 0;
/***** Build path to temporary text file *****/
- snprintf (PathFileTxtTmp,sizeof (PathFileTxtTmp),
- "%s/%s.txt",
+ snprintf (PathFileTxtTmp,sizeof (PathFileTxtTmp),"%s/%s.txt",
Cfg_PATH_MEDIA_TMP_PRIVATE,Media->Name);
/***** Execute system command to get number of frames in GIF *****/
snprintf (Command,sizeof (Command),
- "identify -format '%%n\n' %s | head -1 > %s",
+ "identify -format '%%n\n' %s | head -1 > %s",
PathFileOrg,PathFileTxtTmp);
ReturnCode = system (Command);
if (ReturnCode == -1)
@@ -853,8 +831,7 @@ static void Med_ProcessJPG (struct Med_Media *Media,
/***** Convert original media to temporary JPG processed file
by calling to program that makes the conversion *****/
- snprintf (PathFileJPGTmp,sizeof (PathFileJPGTmp),
- "%s/%s.%s",
+ snprintf (PathFileJPGTmp,sizeof (PathFileJPGTmp),"%s/%s.%s",
Cfg_PATH_MEDIA_TMP_PRIVATE,Media->Name,Med_Extensions[Med_JPG]);
if (Med_ResizeImage (Media,PathFileOrg,PathFileJPGTmp) == 0) // On success ==> 0 is returned
/* Success */
@@ -893,16 +870,15 @@ static void Med_ProcessGIF (struct Med_Media *Media,
/* File size correct */
/***** Get first frame of orifinal GIF file
and save it on temporary PNG file */
- snprintf (PathFilePNGTmp,sizeof (PathFilePNGTmp),
- "%s/%s.png",
+ snprintf (PathFilePNGTmp,sizeof (PathFilePNGTmp),"%s/%s.png",
Cfg_PATH_MEDIA_TMP_PRIVATE,Media->Name);
if (Med_GetFirstFrame (PathFileOrg,PathFilePNGTmp) == 0) // On success ==> 0 is returned
{
/* Success */
/***** Move original GIF file to temporary GIF file *****/
- snprintf (PathFileGIFTmp,sizeof (PathFileGIFTmp),
- "%s/%s.%s",
- Cfg_PATH_MEDIA_TMP_PRIVATE,Media->Name,Med_Extensions[Med_GIF]);
+ snprintf (PathFileGIFTmp,sizeof (PathFileGIFTmp),"%s/%s.%s",
+ Cfg_PATH_MEDIA_TMP_PRIVATE,
+ Media->Name,Med_Extensions[Med_GIF]);
if (rename (PathFileOrg,PathFileGIFTmp)) // Fail
{
/* Remove temporary PNG file */
@@ -960,9 +936,9 @@ static void Med_ProcessVideo (struct Med_Media *Media,
{
/* File size correct */
/***** Move original video file to temporary MP4 file *****/
- snprintf (PathFileTmp,sizeof (PathFileTmp),
- "%s/%s.%s",
- Cfg_PATH_MEDIA_TMP_PRIVATE,Media->Name,Med_Extensions[Media->Type]);
+ snprintf (PathFileTmp,sizeof (PathFileTmp),"%s/%s.%s",
+ Cfg_PATH_MEDIA_TMP_PRIVATE,
+ Media->Name,Med_Extensions[Media->Type]);
if (rename (PathFileOrg,PathFileTmp)) // Fail
/* Show error alert */
Ale_ShowAlert (Ale_ERROR,Txt_The_file_could_not_be_processed_successfully);
@@ -997,7 +973,7 @@ static int Med_ResizeImage (struct Med_Media *Media,
int ReturnCode;
snprintf (Command,sizeof (Command),
- "convert %s -resize '%ux%u>' -quality %u %s",
+ "convert %s -resize '%ux%u>' -quality %u %s",
PathFileOriginal,
Media->Width,
Media->Height,
@@ -1023,8 +999,7 @@ static int Med_GetFirstFrame (const char PathFileOriginal[PATH_MAX + 1],
char Command[128 + PATH_MAX * 2];
int ReturnCode;
- snprintf (Command,sizeof (Command),
- "convert '%s[0]' %s",
+ snprintf (Command,sizeof (Command),"convert '%s[0]' %s",
PathFileOriginal,
PathFileProcessed);
ReturnCode = system (Command);
@@ -1314,8 +1289,7 @@ void Med_MoveMediaToDefinitiveDir (struct Med_Media *Media)
case Med_WEBM:
case Med_OGG:
/***** Create private subdirectory for media if it does not exist *****/
- snprintf (PathMedPriv,sizeof (PathMedPriv),
- "%s/%c%c",
+ snprintf (PathMedPriv,sizeof (PathMedPriv),"%s/%c%c",
Cfg_PATH_MEDIA_PRIVATE,
Media->Name[0],
Media->Name[1]);
@@ -1380,13 +1354,11 @@ static bool Med_MoveTmpFileToDefDir (struct Med_Media *Media,
char PathFile[PATH_MAX + 1]; // Full name of definitive processed file
/***** Temporary processed media file *****/
- snprintf (PathFileTmp,sizeof (PathFileTmp),
- "%s/%s.%s",
+ snprintf (PathFileTmp,sizeof (PathFileTmp),"%s/%s.%s",
Cfg_PATH_MEDIA_TMP_PRIVATE,Media->Name,Extension);
/***** Definitive processed media file *****/
- snprintf (PathFile,sizeof (PathFile),
- "%s/%s.%s",
+ snprintf (PathFile,sizeof (PathFile),"%s/%s.%s",
PathMedPriv,Media->Name,Extension);
/***** Move JPG file *****/
@@ -1459,8 +1431,7 @@ void Med_ShowMedia (const struct Med_Media *Media,
HTM_A_Begin ("href=\"%s\" target=\"_blank\"",Media->URL);
/* Build path to private directory with the media */
- snprintf (PathMedPriv,sizeof (PathMedPriv),
- "%s/%c%c",
+ snprintf (PathMedPriv,sizeof (PathMedPriv),"%s/%c%c",
Cfg_PATH_MEDIA_PRIVATE,
Media->Name[0],
Media->Name[1]);
@@ -1519,8 +1490,7 @@ static void Med_ShowJPG (const struct Med_Media *Media,
bool Cached;
/***** Build private path to JPG *****/
- snprintf (FileNameJPG,sizeof (FileNameJPG),
- "%s.%s",
+ snprintf (FileNameJPG,sizeof (FileNameJPG),"%s.%s",
Media->Name,Med_Extensions[Med_JPG]);
if (asprintf (&FullPathJPGPriv,"%s/%s",
PathMedPriv,FileNameJPG) < 0)
@@ -1539,8 +1509,7 @@ static void Med_ShowJPG (const struct Med_Media *Media,
Brw_CreateDirDownloadTmp ();
Brw_CreateTmpPublicLinkToPrivateFile (FullPathJPGPriv,FileNameJPG);
- snprintf (TmpPubDir,sizeof (TmpPubDir),
- "%s/%s",
+ snprintf (TmpPubDir,sizeof (TmpPubDir),"%s/%s",
Gbl.FileBrowser.TmpPubDir.L,Gbl.FileBrowser.TmpPubDir.R);
Ses_AddPublicDirToCache (FullPathJPGPriv,TmpPubDir);
}
@@ -1579,17 +1548,14 @@ static void Med_ShowGIF (const struct Med_Media *Media,
bool Cached;
/***** Build private path to animated GIF image *****/
- snprintf (FileNameGIF,sizeof (FileNameGIF),
- "%s.%s",
+ snprintf (FileNameGIF,sizeof (FileNameGIF),"%s.%s",
Media->Name,Med_Extensions[Med_GIF]);
if (asprintf (&FullPathGIFPriv,"%s/%s", // The animated GIF image
PathMedPriv,FileNameGIF) < 0)
Lay_NotEnoughMemoryExit ();
/***** Build private path to static PNG image *****/
- snprintf (FileNamePNG,sizeof (FileNamePNG),
- "%s.png",
- Media->Name);
+ snprintf (FileNamePNG,sizeof (FileNamePNG),"%s.png",Media->Name);
if (asprintf (&FullPathPNGPriv,"%s/%s",
PathMedPriv,FileNamePNG) < 0)
Lay_NotEnoughMemoryExit ();
@@ -1608,8 +1574,7 @@ static void Med_ShowGIF (const struct Med_Media *Media,
Brw_CreateTmpPublicLinkToPrivateFile (FullPathGIFPriv,FileNameGIF);
Brw_CreateTmpPublicLinkToPrivateFile (FullPathPNGPriv,FileNamePNG);
- snprintf (TmpPubDir,sizeof (TmpPubDir),
- "%s/%s",
+ snprintf (TmpPubDir,sizeof (TmpPubDir),"%s/%s",
Gbl.FileBrowser.TmpPubDir.L,Gbl.FileBrowser.TmpPubDir.R);
Ses_AddPublicDirToCache (FullPathGIFPriv,TmpPubDir);
}
@@ -1675,8 +1640,7 @@ static void Med_ShowVideo (const struct Med_Media *Media,
bool Cached;
/***** Build private path to video *****/
- snprintf (FileNameVideo,sizeof (FileNameVideo),
- "%s.%s",
+ snprintf (FileNameVideo,sizeof (FileNameVideo),"%s.%s",
Media->Name,Med_Extensions[Media->Type]);
if (asprintf (&FullPathVideoPriv,"%s/%s",
PathMedPriv,FileNameVideo) < 0)
@@ -1695,8 +1659,7 @@ static void Med_ShowVideo (const struct Med_Media *Media,
Brw_CreateDirDownloadTmp ();
Brw_CreateTmpPublicLinkToPrivateFile (FullPathVideoPriv,FileNameVideo);
- snprintf (TmpPubDir,sizeof (TmpPubDir),
- "%s/%s",
+ snprintf (TmpPubDir,sizeof (TmpPubDir),"%s/%s",
Gbl.FileBrowser.TmpPubDir.L,Gbl.FileBrowser.TmpPubDir.R);
Ses_AddPublicDirToCache (FullPathVideoPriv,TmpPubDir);
}
@@ -1876,10 +1839,9 @@ long Med_CloneMedia (const struct Med_Media *MediaSrc)
Length = strlen (MediaSrc->URL);
if (Length > Cns_MAX_BYTES_WWW)
Length = Cns_MAX_BYTES_WWW;
- if ((MediaDst.URL = (char *) malloc (Length + 1)) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for media URL.");
- Str_Copy (MediaDst.URL,MediaSrc->URL,
- Length);
+ if ((MediaDst.URL = malloc (Length + 1)) == NULL)
+ Lay_NotEnoughMemoryExit ();
+ Str_Copy (MediaDst.URL,MediaSrc->URL,Length);
}
/***** Copy media title *****/
@@ -1890,10 +1852,9 @@ long Med_CloneMedia (const struct Med_Media *MediaSrc)
Length = strlen (MediaSrc->Title);
if (Length > Cns_MAX_BYTES_WWW)
Length = Cns_MAX_BYTES_WWW;
- if ((MediaDst.Title = (char *) malloc (Length + 1)) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for media title.");
- Str_Copy (MediaDst.Title,MediaSrc->Title,
- Length);
+ if ((MediaDst.Title = malloc (Length + 1)) == NULL)
+ Lay_NotEnoughMemoryExit ();
+ Str_Copy (MediaDst.Title,MediaSrc->Title,Length);
}
/***** Create duplicate of files *****/
@@ -1918,12 +1879,14 @@ long Med_CloneMedia (const struct Med_Media *MediaSrc)
Fil_CreateDirIfNotExists (MediaPriv[Med_DST].Path);
/* Build paths to private files */
- snprintf (MediaPriv[Med_SRC].FullPath,sizeof (MediaPriv[Med_SRC].FullPath),
- "%s/%s.%s",
- MediaPriv[Med_SRC].Path,MediaSrc->Name,Med_Extensions[MediaSrc->Type]);
- snprintf (MediaPriv[Med_DST].FullPath,sizeof (MediaPriv[Med_DST].FullPath),
- "%s/%s.%s",
- MediaPriv[Med_DST].Path,MediaDst.Name,Med_Extensions[MediaSrc->Type]);
+ snprintf (MediaPriv[Med_SRC].FullPath,
+ sizeof (MediaPriv[Med_SRC].FullPath),"%s/%s.%s",
+ MediaPriv[Med_SRC].Path,
+ MediaSrc->Name,Med_Extensions[MediaSrc->Type]);
+ snprintf (MediaPriv[Med_DST].FullPath,
+ sizeof (MediaPriv[Med_DST].FullPath),"%s/%s.%s",
+ MediaPriv[Med_DST].Path,
+ MediaDst.Name,Med_Extensions[MediaSrc->Type]);
/* Copy file */
Fil_FastCopyOfFiles (MediaPriv[Med_SRC].FullPath,
@@ -1932,11 +1895,11 @@ long Med_CloneMedia (const struct Med_Media *MediaSrc)
if (MediaSrc->Type == Med_GIF)
{
/* Build private paths to PNG */
- snprintf (MediaPriv[Med_SRC].FullPath,sizeof (MediaPriv[Med_SRC].FullPath),
- "%s/%s.png",
+ snprintf (MediaPriv[Med_SRC].FullPath,
+ sizeof (MediaPriv[Med_SRC].FullPath),"%s/%s.png",
MediaPriv[Med_SRC].Path,MediaSrc->Name);
- snprintf (MediaPriv[Med_DST].FullPath,sizeof (MediaPriv[Med_DST].FullPath),
- "%s/%s.png",
+ snprintf (MediaPriv[Med_DST].FullPath,
+ sizeof (MediaPriv[Med_DST].FullPath),"%s/%s.png",
MediaPriv[Med_DST].Path,MediaDst.Name);
/* Copy PNG file */
@@ -2014,8 +1977,7 @@ void Med_RemoveMedia (long MedCod)
if (Media.Name[0])
{
/***** Build path to private directory with the media *****/
- snprintf (PathMedPriv,sizeof (PathMedPriv),
- "%s/%c%c",
+ snprintf (PathMedPriv,sizeof (PathMedPriv),"%s/%c%c",
Cfg_PATH_MEDIA_PRIVATE,
Media.Name[0],
Media.Name[1]);
diff --git a/swad_media.h b/swad_media.h
index 8a6f2701..c2d6bace 100644
--- a/swad_media.h
+++ b/swad_media.h
@@ -144,11 +144,11 @@ void Med_ResetMedia (struct Med_Media *Media);
void Med_GetMediaDataByCod (struct Med_Media *Media);
-void Med_PutMediaUploader (int NumMediaInForm,const char *ClassInput);
-void Med_GetMediaFromForm (long CrsCod,long QstCod,int NumMediaInForm,struct Med_Media *Media,
- void (*GetMediaFromDB) (long CrsCod,long QstCod,int NumMediaInForm,struct Med_Media *Media),
+void Med_PutMediaUploader (int NumMedia,const char *ClassInput);
+void Med_GetMediaFromForm (long CrsCod,long QstCod,int NumMedia,struct Med_Media *Media,
+ void (*GetMediaFromDB) (long CrsCod,long QstCod,int NumMedia,struct Med_Media *Media),
const char *SectionForAlerts);
-void Med_SetParamNames (struct ParamUploadMedia *ParamUploadMedia,int NumMediaInForm);
+void Med_SetParamNames (struct ParamUploadMedia *ParamUpl,int NumMedia);
void Med_RemoveKeepOrStoreMedia (long CurrentMedCodInDB,struct Med_Media *Media);
void Med_MoveMediaToDefinitiveDir (struct Med_Media *Media);
diff --git a/swad_message.c b/swad_message.c
index 5a3fd982..1d625a3a 100644
--- a/swad_message.c
+++ b/swad_message.c
@@ -345,7 +345,7 @@ static void Msg_PutFormMsgUsrs (struct Msg_Messages *Messages,
}
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
if (Messages->ShowOnlyOneRecipient)
Par_PutHiddenParamChar ("ShowOnlyOneRecipient",'Y');
}
@@ -450,7 +450,7 @@ static void Msg_PutParamsShowMorePotentialRecipients (const void *Messages)
Msg_PutHiddenParamMsgCod (((struct Msg_Messages *) Messages)->Reply.OriginalMsgCod);
}
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
/***** Hidden params to send subject and content *****/
Msg_PutHiddenParamsSubjectAndContent ();
@@ -474,7 +474,7 @@ static void Msg_PutParamsWriteMsg (void *Messages)
}
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
{
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
if (((struct Msg_Messages *) Messages)->ShowOnlyOneRecipient)
Par_PutHiddenParamChar ("ShowOnlyOneRecipient",'Y');
}
@@ -627,13 +627,9 @@ static void Msg_WriteFormSubjectAndContentMsgToUsrs (struct Msg_Messages *Messag
row = mysql_fetch_row (mysql_res);
- /* Get subject */
- Str_Copy (Messages->Subject,row[0],
- Cns_MAX_BYTES_SUBJECT);
-
- /* Get content */
- Str_Copy (Content,row[1],
- Cns_MAX_BYTES_LONG_TEXT);
+ /* Get subject (row[0]) and content (row[1]) */
+ Str_Copy (Messages->Subject,row[0],sizeof (Messages->Subject) - 1);
+ Str_Copy (Content ,row[1],Cns_MAX_BYTES_LONG_TEXT);
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
@@ -711,12 +707,10 @@ static void Msg_WriteFormSubjectAndContentMsgToUsrs (struct Msg_Messages *Messag
static void Msg_PutHiddenParamAnotherRecipient (const struct UsrData *UsrDat)
{
- char NicknameWithArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
+ char NickWithArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
- snprintf (NicknameWithArroba,sizeof (NicknameWithArroba),
- "@%s",
- UsrDat->Nickname);
- Par_PutHiddenParamString (NULL,"OtherRecipients",NicknameWithArroba);
+ snprintf (NickWithArroba,sizeof (NickWithArroba),"@%s",UsrDat->Nickname);
+ Par_PutHiddenParamString (NULL,"OtherRecipients",NickWithArroba);
}
/*****************************************************************************/
@@ -839,7 +833,7 @@ void Msg_RecMsgFromUsr (void)
NumRecipients = 0;
while (*Ptr)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDstData.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDstData.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDstData);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDstData,Usr_DONT_GET_PREFS)) // Get recipient's data from the database
@@ -1132,11 +1126,11 @@ static void Msg_GetParamMsgsCrsCod (struct Msg_Messages *Messages)
Crs_GetDataOfCourseByCod (&Crs);
Str_Copy (Messages->FilterCrsShrtName,Crs.ShrtName,
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ sizeof (Messages->FilterCrsShrtName) - 1);
}
else
Str_Copy (Messages->FilterCrsShrtName,Txt_any_course,
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ sizeof (Messages->FilterCrsShrtName) - 1);
}
/*****************************************************************************/
@@ -1184,13 +1178,10 @@ static void Msg_MakeFilterFromToSubquery (const struct Msg_Messages *Messages,
if (strlen (FilterFromToSubquery) + strlen (SearchWord) + 512 >
Msg_MAX_BYTES_MESSAGES_QUERY) // Prevent string overflow
break;
- Str_Concat (FilterFromToSubquery,"%",
- Msg_MAX_BYTES_MESSAGES_QUERY);
- Str_Concat (FilterFromToSubquery,SearchWord,
- Msg_MAX_BYTES_MESSAGES_QUERY);
+ Str_Concat (FilterFromToSubquery,"%",Msg_MAX_BYTES_MESSAGES_QUERY);
+ Str_Concat (FilterFromToSubquery,SearchWord,Msg_MAX_BYTES_MESSAGES_QUERY);
}
- Str_Concat (FilterFromToSubquery,"%'",
- Msg_MAX_BYTES_MESSAGES_QUERY);
+ Str_Concat (FilterFromToSubquery,"%'",Msg_MAX_BYTES_MESSAGES_QUERY);
}
else
FilterFromToSubquery[0] = '\0';
@@ -2797,7 +2788,7 @@ static void Msg_GetDistinctCoursesInMyMessages (struct Msg_Messages *Messages)
{
Messages->Courses[Messages->NumCourses].CrsCod = Crs.CrsCod;
Str_Copy (Messages->Courses[Messages->NumCourses].ShrtName,Crs.ShrtName,
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ sizeof (Messages->Courses[Messages->NumCourses].ShrtName) - 1);
Messages->NumCourses++;
}
}
@@ -2992,8 +2983,7 @@ static void Msg_GetMsgSubject (long MsgCod,char Subject[Cns_MAX_BYTES_SUBJECT +
{
/***** Get subject *****/
row = mysql_fetch_row (mysql_res);
- Str_Copy (Subject,row[0],
- Cns_MAX_BYTES_SUBJECT);
+ Str_Copy (Subject,row[0],Cns_MAX_BYTES_SUBJECT);
}
else
Subject[0] = '\0';
@@ -3028,8 +3018,7 @@ static void Msg_GetMsgContent (long MsgCod,char Content[Cns_MAX_BYTES_LONG_TEXT
row = mysql_fetch_row (mysql_res);
/****** Get content (row[0]) *****/
- Str_Copy (Content,row[0],
- Cns_MAX_BYTES_LONG_TEXT);
+ Str_Copy (Content,row[0],Cns_MAX_BYTES_LONG_TEXT);
/***** Get media (row[1]) *****/
Media->MedCod = Str_ConvertStrCodToLongCod (row[1]);
@@ -3324,17 +3313,15 @@ void Msg_GetNotifMessage (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
SummaryStr[Ntf_MAX_BYTES_SUMMARY] = '\0';
}
else
- Str_Copy (SummaryStr,row[0],
- Ntf_MAX_BYTES_SUMMARY);
+ Str_Copy (SummaryStr,row[0],Ntf_MAX_BYTES_SUMMARY);
/***** Copy subject *****/
if (GetContent)
{
Length = strlen (row[1]);
- if ((*ContentStr = (char *) malloc (Length + 1)) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for notification content.");
- Str_Copy (*ContentStr,row[1],
- Length);
+ if ((*ContentStr = malloc (Length + 1)) == NULL)
+ Lay_NotEnoughMemoryExit ();
+ Str_Copy (*ContentStr,row[1],Length);
}
}
@@ -3546,7 +3533,7 @@ static void Msg_WriteFormToReply (long MsgCod,long CrsCod,
Grp_PutParamAllGroups ();
Par_PutHiddenParamChar ("IsReply",'Y');
Msg_PutHiddenParamMsgCod (MsgCod);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
Par_PutHiddenParamChar ("ShowOnlyOneRecipient",'Y');
/****** Link and form end *****/
@@ -3887,7 +3874,7 @@ static void Msg_PutFormToBanSender (struct Msg_Messages *Messages,
Frm_StartForm (ActBanUsrMsg);
Pag_PutHiddenParamPagNum (Msg_WhatPaginate[Messages->TypeOfMessages],
Messages->CurrentPage);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
Msg_PutHiddenParamsMsgsFilters (Messages);
Ico_PutIconLink ("unlock.svg",Txt_Sender_permitted_click_to_ban_him);
Frm_EndForm ();
@@ -3905,7 +3892,7 @@ static void Msg_PutFormToUnbanSender (struct Msg_Messages *Messages,
Frm_StartForm (ActUnbUsrMsg);
Pag_PutHiddenParamPagNum (Msg_WhatPaginate[Messages->TypeOfMessages],
Messages->CurrentPage);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
Msg_PutHiddenParamsMsgsFilters (Messages);
Ico_PutIconLink ("lock.svg",Txt_Sender_banned_click_to_unban_him);
Frm_EndForm ();
@@ -4078,7 +4065,7 @@ void Msg_ListBannedUsrs (void)
/* Put form to unban user */
HTM_TD_Begin ("class=\"BM\"");
Frm_StartForm (ActUnbUsrLst);
- Usr_PutParamUsrCodEncrypted (UsrDat.EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat.EnUsrCod);
Ico_PutIconLink ("lock.svg",Txt_Sender_banned_click_to_unban_him);
Frm_EndForm ();
HTM_TD_End ();
diff --git a/swad_network.c b/swad_network.c
index 8640a365..6f2f5bab 100644
--- a/swad_network.c
+++ b/swad_network.c
@@ -231,8 +231,7 @@ void Net_ShowWebsAndSocialNets (const struct UsrData *UsrDat)
{
/* Get URL */
row = mysql_fetch_row (mysql_res);
- Str_Copy (URL,row[0],
- Cns_MAX_BYTES_WWW);
+ Str_Copy (URL,row[0],sizeof (URL) - 1);
/* Show the web / social network */
Net_ShowAWebOrSocialNet (URL,
@@ -284,9 +283,7 @@ void Net_ShowFormMyWebsAndSocialNets (void)
HTM_SECTION_Begin (Net_MY_WEBS_ID);
/***** Begin box *****/
- snprintf (StrRecordWidth,sizeof (StrRecordWidth),
- "%upx",
- Rec_RECORD_WIDTH);
+ snprintf (StrRecordWidth,sizeof (StrRecordWidth),"%upx",Rec_RECORD_WIDTH);
Box_BoxBegin (StrRecordWidth,Txt_Webs_social_networks,
Net_PutIconsWebsSocialNetworks,NULL,
Hlp_PROFILE_Webs,Box_NOT_CLOSABLE);
@@ -313,8 +310,7 @@ void Net_ShowFormMyWebsAndSocialNets (void)
row = mysql_fetch_row (mysql_res);
/* Get URL */
- Str_Copy (URL,row[0],
- Cns_MAX_BYTES_WWW);
+ Str_Copy (URL,row[0],sizeof (URL) - 1);
}
else
URL[0] = '\0';
@@ -323,9 +319,7 @@ void Net_ShowFormMyWebsAndSocialNets (void)
DB_FreeMySQLResult (&mysql_res);
/***** Row for this web / social network *****/
- snprintf (StrName,sizeof (StrName),
- "URL%u",
- (unsigned) NumURL);
+ snprintf (StrName,sizeof (StrName),"URL%u",(unsigned) NumURL);
HTM_TR_Begin (NULL);
HTM_TD_Begin ("class=\"REC_C1_BOT LM\"");
@@ -400,9 +394,7 @@ static void Net_GetMyWebsAndSocialNetsFromForm (void)
NumURL++)
{
/***** Get URL from the form *****/
- snprintf (ParamName,sizeof (ParamName),
- "URL%u",
- (unsigned) NumURL);
+ snprintf (ParamName,sizeof (ParamName),"URL%u",(unsigned) NumURL);
Par_GetParToText (ParamName,URL,Cns_MAX_BYTES_WWW);
if (URL[0])
@@ -573,8 +565,7 @@ void Net_ShowWebAndSocialNetworksStats (void)
row = mysql_fetch_row (mysql_res);
/* Get web / social network (row[0]) */
- Str_Copy (NetName,row[0],
- Net_MAX_BYTES_NETWORK_NAME);
+ Str_Copy (NetName,row[0],sizeof (NetName) - 1);
for (Web = (Net_WebsAndSocialNetworks_t) 0;
Web <= (Net_WebsAndSocialNetworks_t) (Net_NUM_WEBS_AND_SOCIAL_NETWORKS - 1);
Web++)
diff --git a/swad_nickname.c b/swad_nickname.c
index 2281787e..cc221c00 100644
--- a/swad_nickname.c
+++ b/swad_nickname.c
@@ -74,21 +74,20 @@ static void Nck_UpdateUsrNick (struct UsrData *UsrDat);
/********* Check whether a nickname (with initial arroba) if valid ***********/
/*****************************************************************************/
-bool Nck_CheckIfNickWithArrobaIsValid (const char *NicknameWithArroba)
+bool Nck_CheckIfNickWithArrobaIsValid (const char *NickWithArroba)
{
- char NicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
+ char NickWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
unsigned Length;
const char *Ptr;
/***** A nickname must start by '@' *****/
- if (NicknameWithArroba[0] != '@') // It's not a nickname
+ if (NickWithArroba[0] != '@') // It's not a nickname
return false;
/***** Make a copy of nickname *****/
- Str_Copy (NicknameWithoutArroba,NicknameWithArroba,
- Nck_MAX_BYTES_NICKNAME_FROM_FORM);
- Str_RemoveLeadingArrobas (NicknameWithoutArroba);
- Length = strlen (NicknameWithoutArroba);
+ Str_Copy (NickWithoutArroba,NickWithArroba,sizeof (NickWithoutArroba) - 1);
+ Str_RemoveLeadingArrobas (NickWithoutArroba);
+ Length = strlen (NickWithoutArroba);
/***** A nick (without arroba) must have a number of characters
Nck_MIN_BYTES_NICKNAME_WITHOUT_ARROBA <= Length <= Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA *****/
@@ -97,7 +96,7 @@ bool Nck_CheckIfNickWithArrobaIsValid (const char *NicknameWithArroba)
return false;
/***** A nick can have digits, letters and '_' *****/
- for (Ptr = NicknameWithoutArroba;
+ for (Ptr = NickWithoutArroba;
*Ptr;
Ptr++)
if (!((*Ptr >= 'a' && *Ptr <= 'z') ||
@@ -128,8 +127,7 @@ bool Nck_GetNicknameFromUsrCod (long UsrCod,
{
/* Get nickname */
row = mysql_fetch_row (mysql_res);
- Str_Copy (Nickname,row[0],
- Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA);
+ Str_Copy (Nickname,row[0],Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA);
Found = true;
}
else
@@ -152,7 +150,7 @@ bool Nck_GetNicknameFromUsrCod (long UsrCod,
long Nck_GetUsrCodFromNickname (const char *Nickname)
{
- char NicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
+ char NickWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
long UsrCod = -1L;
@@ -161,9 +159,8 @@ long Nck_GetUsrCodFromNickname (const char *Nickname)
if (Nickname[0])
{
/***** Make a copy without possible starting arrobas *****/
- Str_Copy (NicknameWithoutArroba,Nickname,
- Nck_MAX_BYTES_NICKNAME_FROM_FORM);
- Str_RemoveLeadingArrobas (NicknameWithoutArroba);
+ Str_Copy (NickWithoutArroba,Nickname,sizeof (NickWithoutArroba) - 1);
+ Str_RemoveLeadingArrobas (NickWithoutArroba);
/***** Get user's code from database *****/
/* Check if user code from table usr_nicknames is also in table usr_data */
@@ -172,7 +169,7 @@ long Nck_GetUsrCodFromNickname (const char *Nickname)
" FROM usr_nicknames,usr_data"
" WHERE usr_nicknames.Nickname='%s'"
" AND usr_nicknames.UsrCod=usr_data.UsrCod",
- NicknameWithoutArroba))
+ NickWithoutArroba))
{
/* Get row */
row = mysql_fetch_row (mysql_res);
@@ -230,7 +227,7 @@ static void Nck_ShowFormChangeUsrNickname (bool ItsMe,
unsigned NumNicks;
unsigned NumNick;
Act_Action_t NextAction;
- char NicknameWithArroba[1 + Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA + 1];
+ char NickWithArroba[1 + Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA + 1];
const struct UsrData *UsrDat = (ItsMe ? &Gbl.Usrs.Me.UsrDat :
&Gbl.Usrs.Other.UsrDat);
@@ -246,9 +243,7 @@ static void Nck_ShowFormChangeUsrNickname (bool ItsMe,
UsrDat->UsrCod);
/***** Begin box *****/
- snprintf (StrRecordWidth,sizeof (StrRecordWidth),
- "%upx",
- Rec_RECORD_WIDTH);
+ snprintf (StrRecordWidth,sizeof (StrRecordWidth),"%upx",Rec_RECORD_WIDTH);
Box_BoxBegin (StrRecordWidth,Txt_Nickname,
Acc_PutLinkToRemoveMyAccount,NULL,
Hlp_PROFILE_Account,Box_NOT_CLOSABLE);
@@ -325,7 +320,7 @@ static void Nck_ShowFormChangeUsrNickname (bool ItsMe,
/* Link to QR code */
if (NumNick == 1 && UsrDat->Nickname[0])
QR_PutLinkToPrintQRCode (ActPrnUsrQR,
- Usr_PutParamMyUsrCodEncrypted,Gbl.Usrs.Me.UsrDat.EncryptedUsrCod);
+ Usr_PutParamMyUsrCodEncrypted,Gbl.Usrs.Me.UsrDat.EnUsrCod);
/* Form to change the nickname */
if (NumNick > 1)
@@ -349,13 +344,11 @@ static void Nck_ShowFormChangeUsrNickname (bool ItsMe,
break;
}
Frm_StartFormAnchor (NextAction,Nck_NICKNAME_SECTION_ID);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
}
- snprintf (NicknameWithArroba,sizeof (NicknameWithArroba),
- "@%s",
- row[0]);
- Par_PutHiddenParamString (NULL,"NewNick",NicknameWithArroba); // Nickname
+ snprintf (NickWithArroba,sizeof (NickWithArroba),"@%s",row[0]);
+ Par_PutHiddenParamString (NULL,"NewNick",NickWithArroba); // Nickname
Btn_PutConfirmButtonInline (Txt_Use_this_nickname);
Frm_EndForm ();
}
@@ -398,13 +391,12 @@ static void Nck_ShowFormChangeUsrNickname (bool ItsMe,
break;
}
Frm_StartFormAnchor (NextAction,Nck_NICKNAME_SECTION_ID);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
}
- snprintf (NicknameWithArroba,sizeof (NicknameWithArroba),
- "@%s",
+ snprintf (NickWithArroba,sizeof (NickWithArroba),"@%s",
Gbl.Usrs.Me.UsrDat.Nickname);
HTM_INPUT_TEXT ("NewNick",1 + Nck_MAX_CHARS_NICKNAME_WITHOUT_ARROBA,
- NicknameWithArroba,HTM_DONT_SUBMIT_ON_CHANGE,
+ NickWithArroba,HTM_DONT_SUBMIT_ON_CHANGE,
"id=\"NewNick\" size=\"18\"");
HTM_BR ();
Btn_PutCreateButtonInline (NumNicks ? Txt_Change_nickname : // I already have a nickname
@@ -431,7 +423,7 @@ static void Nck_PutParamsRemoveOtherNick (void *Nick)
{
if (Nick)
{
- Usr_PutParamUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
Par_PutHiddenParamString (NULL,"Nick",Nick);
}
}
@@ -444,21 +436,21 @@ void Nck_RemoveMyNick (void)
{
extern const char *Txt_Nickname_X_removed;
extern const char *Txt_You_can_not_delete_your_current_nickname;
- char NicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA + 1];
+ char NickWithoutArroba[Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA + 1];
/***** Get nickname from form *****/
- Par_GetParToText ("Nick",NicknameWithoutArroba,
+ Par_GetParToText ("Nick",NickWithoutArroba,
Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA);
- if (strcasecmp (NicknameWithoutArroba,Gbl.Usrs.Me.UsrDat.Nickname)) // Only if not my current nickname
+ if (strcasecmp (NickWithoutArroba,Gbl.Usrs.Me.UsrDat.Nickname)) // Only if not my current nickname
{
/***** Remove one of my old nicknames *****/
- Nck_RemoveNicknameFromDB (Gbl.Usrs.Me.UsrDat.UsrCod,NicknameWithoutArroba);
+ Nck_RemoveNicknameFromDB (Gbl.Usrs.Me.UsrDat.UsrCod,NickWithoutArroba);
/***** Show message *****/
Ale_CreateAlert (Ale_SUCCESS,Nck_NICKNAME_SECTION_ID,
Txt_Nickname_X_removed,
- NicknameWithoutArroba);
+ NickWithoutArroba);
}
else
Ale_CreateAlert (Ale_WARNING,Nck_NICKNAME_SECTION_ID,
@@ -475,7 +467,7 @@ void Nck_RemoveMyNick (void)
void Nck_RemoveOtherUsrNick (void)
{
extern const char *Txt_Nickname_X_removed;
- char NicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA + 1];
+ char NickWithoutArroba[Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA + 1];
/***** Get user whose nick must be removed *****/
if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
@@ -483,16 +475,16 @@ void Nck_RemoveOtherUsrNick (void)
if (Usr_ICanEditOtherUsr (&Gbl.Usrs.Other.UsrDat))
{
/***** Get nickname from form *****/
- Par_GetParToText ("Nick",NicknameWithoutArroba,
+ Par_GetParToText ("Nick",NickWithoutArroba,
Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA);
/***** Remove one of the old nicknames *****/
- Nck_RemoveNicknameFromDB (Gbl.Usrs.Other.UsrDat.UsrCod,NicknameWithoutArroba);
+ Nck_RemoveNicknameFromDB (Gbl.Usrs.Other.UsrDat.UsrCod,NickWithoutArroba);
/***** Show message *****/
Ale_CreateAlert (Ale_SUCCESS,Nck_NICKNAME_SECTION_ID,
Txt_Nickname_X_removed,
- NicknameWithoutArroba);
+ NickWithoutArroba);
/***** Show user's account again *****/
Acc_ShowFormChgOtherUsrAccount ();
@@ -564,57 +556,55 @@ static void Nck_UpdateUsrNick (struct UsrData *UsrDat)
extern const char *Txt_The_nickname_X_had_been_registered_by_another_user;
extern const char *Txt_The_nickname_X_has_been_registered_successfully;
extern const char *Txt_The_nickname_entered_X_is_not_valid_;
- char NewNicknameWithArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
- char NewNicknameWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
+ char NewNickWithArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
+ char NewNickWithoutArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
/***** Get new nickname from form *****/
- Par_GetParToText ("NewNick",NewNicknameWithArroba,
+ Par_GetParToText ("NewNick",NewNickWithArroba,
Nck_MAX_BYTES_NICKNAME_FROM_FORM);
- if (Nck_CheckIfNickWithArrobaIsValid (NewNicknameWithArroba)) // If new nickname is valid
+ if (Nck_CheckIfNickWithArrobaIsValid (NewNickWithArroba)) // If new nickname is valid
{
/***** Remove arrobas at the beginning *****/
- Str_Copy (NewNicknameWithoutArroba,NewNicknameWithArroba,
- Nck_MAX_BYTES_NICKNAME_FROM_FORM);
- Str_RemoveLeadingArrobas (NewNicknameWithoutArroba);
+ Str_Copy (NewNickWithoutArroba,NewNickWithArroba,sizeof (NewNickWithoutArroba) - 1);
+ Str_RemoveLeadingArrobas (NewNickWithoutArroba);
/***** Check if new nickname exists in database *****/
- if (!strcmp (UsrDat->Nickname,NewNicknameWithoutArroba)) // User's nickname match exactly the new nickname
+ if (!strcmp (UsrDat->Nickname,NewNickWithoutArroba)) // User's nickname match exactly the new nickname
Ale_CreateAlert (Ale_WARNING,Nck_NICKNAME_SECTION_ID,
Txt_The_nickname_X_matches_the_one_you_had_previously_registered,
- NewNicknameWithoutArroba);
- else if (strcasecmp (UsrDat->Nickname,NewNicknameWithoutArroba)) // User's nickname does not match, not even case insensitive, the new nickname
+ NewNickWithoutArroba);
+ else if (strcasecmp (UsrDat->Nickname,NewNickWithoutArroba)) // User's nickname does not match, not even case insensitive, the new nickname
{
/***** Check if the new nickname matches any of my old nicknames *****/
if (!DB_QueryCOUNT ("can not check if nickname already existed",
"SELECT COUNT(*) FROM usr_nicknames"
" WHERE UsrCod=%ld AND Nickname='%s'",
- UsrDat->UsrCod,NewNicknameWithoutArroba)) // No matches
+ UsrDat->UsrCod,NewNickWithoutArroba)) // No matches
/***** Check if the new nickname matches any of the nicknames of other users *****/
if (DB_QueryCOUNT ("can not check if nickname already existed",
"SELECT COUNT(*) FROM usr_nicknames"
" WHERE Nickname='%s' AND UsrCod<>%ld",
- NewNicknameWithoutArroba,UsrDat->UsrCod)) // A nickname of another user is the same that user's nickname
+ NewNickWithoutArroba,UsrDat->UsrCod)) // A nickname of another user is the same that user's nickname
Ale_CreateAlert (Ale_WARNING,Nck_NICKNAME_SECTION_ID,
Txt_The_nickname_X_had_been_registered_by_another_user,
- NewNicknameWithoutArroba);
+ NewNickWithoutArroba);
}
if (Ale_GetNumAlerts () == 0) // No problems
{
// Now we know the new nickname is not already in database
// and is diffent to the current one
- Nck_UpdateNickInDB (UsrDat->UsrCod,NewNicknameWithoutArroba);
- Str_Copy (UsrDat->Nickname,NewNicknameWithoutArroba,
- Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA);
+ Nck_UpdateNickInDB (UsrDat->UsrCod,NewNickWithoutArroba);
+ Str_Copy (UsrDat->Nickname,NewNickWithoutArroba,sizeof (UsrDat->Nickname) - 1);
Ale_CreateAlert (Ale_SUCCESS,Nck_NICKNAME_SECTION_ID,
Txt_The_nickname_X_has_been_registered_successfully,
- NewNicknameWithoutArroba);
+ NewNickWithoutArroba);
}
}
else // New nickname is not valid
Ale_CreateAlert (Ale_WARNING,Nck_NICKNAME_SECTION_ID,
Txt_The_nickname_entered_X_is_not_valid_,
- NewNicknameWithArroba,
+ NewNickWithArroba,
Nck_MIN_CHARS_NICKNAME_WITHOUT_ARROBA,
Nck_MAX_CHARS_NICKNAME_WITHOUT_ARROBA);
}
diff --git a/swad_nickname.h b/swad_nickname.h
index ec86b03c..1f9b46ac 100644
--- a/swad_nickname.h
+++ b/swad_nickname.h
@@ -46,7 +46,7 @@
/***************************** Public prototypes *****************************/
/*****************************************************************************/
-bool Nck_CheckIfNickWithArrobaIsValid (const char *NicknameWithArroba);
+bool Nck_CheckIfNickWithArrobaIsValid (const char *NickWithArroba);
bool Nck_GetNicknameFromUsrCod (long UsrCod,
char Nickname[Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA + 1]);
diff --git a/swad_notice.c b/swad_notice.c
index 59e87b16..0b7b103e 100644
--- a/swad_notice.c
+++ b/swad_notice.c
@@ -29,7 +29,6 @@
#include // For PATH_MAX
#include // For NULL
#include // For sscanf, asprintf, etc.
-#include // For exit, system, malloc, calloc, free, etc.
#include
#include "swad_box.h"
@@ -407,8 +406,7 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing,long HighlightNotCod)
if (TypeNoticesListing == Not_LIST_FULL_NOTICES)
{
/***** Begin box *****/
- snprintf (StrWidth,sizeof (StrWidth),
- "%upx",
+ snprintf (StrWidth,sizeof (StrWidth),"%upx",
Not_ContainerWidth[Not_LIST_FULL_NOTICES] + 50);
Box_BoxBegin (StrWidth,Txt_Notices,
Not_PutIconsListNotices,NULL,
@@ -435,8 +433,7 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing,long HighlightNotCod)
UsrCod = Str_ConvertStrCodToLongCod (row[2]);
/* Get the content (row[3]) and insert links */
- Str_Copy (Content,row[3],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Content,row[3],sizeof (Content) - 1);
/* Inserting links is incompatible with limiting the length
==> don't insert links when limiting length */
@@ -469,8 +466,7 @@ void Not_ShowNotices (Not_Listing_t TypeNoticesListing,long HighlightNotCod)
case Not_LIST_BRIEF_NOTICES:
/***** Link to RSS file *****/
/* Create RSS file if not exists */
- snprintf (PathRelRSSFile,sizeof (PathRelRSSFile),
- "%s/%ld/%s/%s",
+ snprintf (PathRelRSSFile,sizeof (PathRelRSSFile),"%s/%ld/%s/%s",
Cfg_PATH_CRS_PUBLIC,
Gbl.Hierarchy.Crs.CrsCod,Cfg_RSS_FOLDER,Cfg_RSS_FILE);
if (!Fil_CheckIfPathExists (PathRelRSSFile))
@@ -586,8 +582,7 @@ static void Not_GetDataAndShowNotice (long NotCod)
UsrCod = Str_ConvertStrCodToLongCod (row[1]);
/* Get the content (row[2]) and insert links*/
- Str_Copy (Content,row[2],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Content,row[2],sizeof (Content) - 1);
Str_InsertLinks (Content,Cns_MAX_BYTES_TEXT,
Not_MaxCharsURLOnScreen[Not_LIST_FULL_NOTICES]);
@@ -794,17 +789,15 @@ void Not_GetSummaryAndContentNotice (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
SummaryStr[Ntf_MAX_BYTES_SUMMARY] = '\0';
}
else
- Str_Copy (SummaryStr,row[0],
- Ntf_MAX_BYTES_SUMMARY);
+ Str_Copy (SummaryStr,row[0],Ntf_MAX_BYTES_SUMMARY);
/***** Copy content *****/
if (GetContent)
{
Length = strlen (row[0]);
- if ((*ContentStr = (char *) malloc (Length + 1)) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for notification content.");
- Str_Copy (*ContentStr,row[0],
- Length);
+ if ((*ContentStr = malloc (Length + 1)) == NULL)
+ Lay_NotEnoughMemoryExit ();
+ Str_Copy (*ContentStr,row[0],Length);
}
}
diff --git a/swad_notification.c b/swad_notification.c
index cf51b365..a51e5f68 100644
--- a/swad_notification.c
+++ b/swad_notification.c
@@ -726,16 +726,16 @@ static bool Ntf_StartFormGoToAction (Ntf_NotifyEvent_t NotifyEvent,
// Cod is the code of the social publishing
Frm_StartForm (ActSeeTmlGbl);
TL_Pub_PutHiddenParamPubCod (Cod);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
Ntf_PutHiddenParamNotifyEvent (NotifyEvent);
break;
case Ntf_EVENT_FOLLOWER:
- if (UsrDat->EncryptedUsrCod[0]) // User's code found ==>
+ if (UsrDat->EnUsrCod[0]) // User's code found ==>
// go to user's public profile
{
Frm_StartForm (ActSeeOthPubPrf);
/* Put param to go to follower's profile */
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
}
else // No user's code found ==> go to see my followers
Frm_StartForm (ActSeeFlr);
diff --git a/swad_pagination.c b/swad_pagination.c
index 1b183df1..a6b3a14f 100644
--- a/swad_pagination.c
+++ b/swad_pagination.c
@@ -263,7 +263,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
Frm_StartFormAnchor (ActSeeUsrAgd,Pagination->Anchor);
Agd_PutHiddenParamEventsOrder (((struct Agd_Agenda *) Context)->SelectedOrder);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
break;
default:
break;
@@ -390,7 +390,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
Frm_StartFormAnchor (ActSeeUsrAgd,Pagination->Anchor);
Agd_PutHiddenParamEventsOrder (((struct Agd_Agenda *) Context)->SelectedOrder);
Pag_PutHiddenParamPagNum (WhatPaginate,1);
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
break;
default:
break;
@@ -503,7 +503,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
Frm_StartFormAnchor (ActSeeUsrAgd,Pagination->Anchor);
Agd_PutHiddenParamEventsOrder (((struct Agd_Agenda *) Context)->SelectedOrder);
Pag_PutHiddenParamPagNum (WhatPaginate,Pagination->LeftPage);
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
break;
default:
break;
@@ -628,7 +628,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
Frm_StartFormAnchor (ActSeeUsrAgd,Pagination->Anchor);
Agd_PutHiddenParamEventsOrder (((struct Agd_Agenda *) Context)->SelectedOrder);
Pag_PutHiddenParamPagNum (WhatPaginate,NumPage);
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
break;
default:
break;
@@ -740,7 +740,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
Frm_StartFormAnchor (ActSeeUsrAgd,Pagination->Anchor);
Agd_PutHiddenParamEventsOrder (((struct Agd_Agenda *) Context)->SelectedOrder);
Pag_PutHiddenParamPagNum (WhatPaginate,Pagination->RightPage);
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
break;
default:
break;
@@ -853,7 +853,7 @@ void Pag_WriteLinksToPages (Pag_WhatPaginate_t WhatPaginate,
Frm_StartFormAnchor (ActSeeUsrAgd,Pagination->Anchor);
Agd_PutHiddenParamEventsOrder (((struct Agd_Agenda *) Context)->SelectedOrder);
Pag_PutHiddenParamPagNum (WhatPaginate,Pagination->NumPags);
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
break;
default:
break;
diff --git a/swad_parameter.c b/swad_parameter.c
index e580f427..1c2dcdfb 100644
--- a/swad_parameter.c
+++ b/swad_parameter.c
@@ -86,8 +86,7 @@ bool Par_GetQueryString (void)
char UnsignedLongStr[Cns_MAX_DECIMAL_DIGITS_ULONG + 1];
unsigned long UnsignedLong;
- Str_Copy (Method,getenv ("REQUEST_METHOD"),
- Par_MAX_BYTES_METHOD);
+ Str_Copy (Method,getenv ("REQUEST_METHOD"),sizeof (Method) - 1);
if (!strcmp (Method,"GET"))
{
@@ -99,7 +98,7 @@ bool Par_GetQueryString (void)
Gbl.Params.ContentLength = strlen (getenv ("QUERY_STRING"));
/* Allocate memory for query string */
- if ((Gbl.Params.QueryString = (char *) malloc (Gbl.Params.ContentLength + 1)) == NULL)
+ if ((Gbl.Params.QueryString = malloc (Gbl.Params.ContentLength + 1)) == NULL)
return false;
/* Copy query string from environment variable */
@@ -113,7 +112,7 @@ bool Par_GetQueryString (void)
if (getenv ("CONTENT_LENGTH"))
{
Str_Copy (UnsignedLongStr,getenv ("CONTENT_LENGTH"),
- Cns_MAX_DECIMAL_DIGITS_ULONG);
+ sizeof (UnsignedLongStr) - 1);
if (sscanf (UnsignedLongStr,"%lu",&UnsignedLong) != 1)
return false;
Gbl.Params.ContentLength = (size_t) UnsignedLong;
@@ -127,8 +126,7 @@ bool Par_GetQueryString (void)
if (getenv ("CONTENT_TYPE") == NULL)
return false;
- Str_Copy (ContentType,getenv ("CONTENT_TYPE"),
- Par_MAX_BYTES_CONTENT_TYPE);
+ Str_Copy (ContentType,getenv ("CONTENT_TYPE"),sizeof (ContentType) - 1);
if (!strncmp (ContentType,"multipart/form-data",strlen ("multipart/form-data")))
{
@@ -145,7 +143,7 @@ bool Par_GetQueryString (void)
Gbl.ContentReceivedByCGI = Act_CONT_NORM;
/* Allocate memory for query string */
- if ((Gbl.Params.QueryString = (char *) malloc (Gbl.Params.ContentLength + 1)) == NULL)
+ if ((Gbl.Params.QueryString = malloc (Gbl.Params.ContentLength + 1)) == NULL)
return false;
/* Copy query string from stdin */
@@ -185,11 +183,9 @@ static void Par_GetBoundary (void)
/***** Create boundary strings *****/
snprintf (Gbl.Boundary.StrWithoutCRLF,sizeof (Gbl.Boundary.StrWithoutCRLF),
- "--%s",
- PtrToBoundary);
+ "--%s",PtrToBoundary);
snprintf (Gbl.Boundary.StrWithCRLF,sizeof (Gbl.Boundary.StrWithCRLF),
- "%c%c%s",
- 0x0D,0x0A,Gbl.Boundary.StrWithoutCRLF);
+ "%c%c%s",0x0D,0x0A,Gbl.Boundary.StrWithoutCRLF);
/***** Compute lengths *****/
Gbl.Boundary.LengthWithoutCRLF = strlen (Gbl.Boundary.StrWithoutCRLF);
@@ -261,8 +257,8 @@ static void Par_CreateListOfParamsFromQueryString (void)
)
{
/* Allocate space for a new parameter initialized to 0 */
- if ((NewParam = (struct Param *) calloc (1,sizeof (struct Param))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for parameter");
+ if ((NewParam = calloc (1,sizeof (*NewParam))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/* Link the previous element in list with the current element */
if (CurPos == 0)
@@ -337,8 +333,8 @@ static void Par_CreateListOfParamsFromTmpFile (void)
if (!strcasecmp (StrAux,StringBeforeParam)) // Start of a parameter
{
/* Allocate space for a new parameter initialized to 0 */
- if ((NewParam = (struct Param *) calloc (1,sizeof (struct Param))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for parameter");
+ if ((NewParam = calloc (1,sizeof (*NewParam))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/* Link the previous element in list with the current element */
if (CurPos == 0)
@@ -699,7 +695,7 @@ void Par_GetMainParameters (void)
/* Set another user's nickname */
Str_RemoveLeadingArrobas (Nickname);
Str_Copy (Gbl.Usrs.Other.UsrDat.Nickname,Nickname, // without arroba
- Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA);
+ sizeof (Gbl.Usrs.Other.UsrDat.Nickname) - 1);
// This user's code is used to go to public profile
// and to refresh old publishings in user's timeline
@@ -715,7 +711,7 @@ void Par_GetMainParameters (void)
/* Set another user's nickname */
Str_RemoveLeadingArrobas (Nickname);
Str_Copy (Gbl.Usrs.Other.UsrDat.Nickname,Nickname, // without arroba
- Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA);
+ sizeof (Gbl.Usrs.Other.UsrDat.Nickname) - 1);
// This user's code is used to go to public agenda
// If user does not exist ==> UsrCod = -1
@@ -801,18 +797,14 @@ void Par_GetMainParameters (void)
Gbl.Prefs.Theme = The_THEME_DEFAULT;
/***** Set path of theme *****/
- snprintf (URL,sizeof (URL),
- "%s/%s",
+ snprintf (URL,sizeof (URL),"%s/%s",
Cfg_URL_ICON_THEMES_PUBLIC,The_ThemeId[Gbl.Prefs.Theme]);
- Str_Copy (Gbl.Prefs.URLTheme,URL,
- PATH_MAX);
+ Str_Copy (Gbl.Prefs.URLTheme,URL,sizeof (Gbl.Prefs.URLTheme) - 1);
/***** Set path of icon set *****/
- snprintf (URL,sizeof (URL),
- "%s/%s",
+ snprintf (URL,sizeof (URL),"%s/%s",
Cfg_URL_ICON_SETS_PUBLIC,Ico_IconSetId[Gbl.Prefs.IconSet]);
- Str_Copy (Gbl.Prefs.URLIconSet,URL,
- PATH_MAX);
+ Str_Copy (Gbl.Prefs.URLIconSet,URL,sizeof (Gbl.Prefs.URLIconSet) - 1);
}
/***** Get country if exists (from menu) *****/
diff --git a/swad_password.c b/swad_password.c
index aef454d5..1fc45fa4 100644
--- a/swad_password.c
+++ b/swad_password.c
@@ -127,7 +127,7 @@ bool Pwd_CheckPendingPassword (void)
/* Get encrypted pending password */
row = mysql_fetch_row (mysql_res);
Str_Copy (Gbl.Usrs.Me.PendingPassword,row[0],
- Pwd_BYTES_ENCRYPTED_PASSWORD);
+ sizeof (Gbl.Usrs.Me.PendingPassword) - 1);
}
else
Gbl.Usrs.Me.PendingPassword[0] = '\0';
@@ -155,7 +155,7 @@ void Pwd_AssignMyPendingPasswordToMyCurrentPassword (void)
/***** Update my current password *****/
Str_Copy (Gbl.Usrs.Me.UsrDat.Password,Gbl.Usrs.Me.PendingPassword,
- Pwd_BYTES_ENCRYPTED_PASSWORD);
+ sizeof (Gbl.Usrs.Me.UsrDat.Password) - 1);
/***** Remove my pending password from database
since it is not longer necessary *****/
@@ -235,7 +235,7 @@ static void Pwd_CheckAndUpdateNewPwd (struct UsrData *UsrDat)
{
/* Update user's data */
Str_Copy (UsrDat->Password,NewEncryptedPassword,
- Pwd_BYTES_ENCRYPTED_PASSWORD);
+ sizeof (UsrDat->Password) - 1);
Ses_UpdateSessionDataInDB ();
Enr_UpdateUsrData (UsrDat);
@@ -364,7 +364,7 @@ void Pwd_ChkIdLoginAndSendNewPwd (void)
// User has typed a user's ID
Str_Copy (Gbl.Usrs.Me.UsrDat.IDs.List[0].ID,Gbl.Usrs.Me.UsrIdLogin,
- ID_MAX_BYTES_USR_ID);
+ sizeof (Gbl.Usrs.Me.UsrDat.IDs.List[0].ID) - 1);
Str_ConvertToUpperText (Gbl.Usrs.Me.UsrDat.IDs.List[0].ID);
/* Get users' codes for this ID */
@@ -669,9 +669,7 @@ void Pwd_ShowFormChgMyPwd (void)
Frm_StartFormAnchor (ActChgMyPwd,Pwd_PASSWORD_SECTION_ID);
/***** Begin box *****/
- snprintf (StrRecordWidth,sizeof (StrRecordWidth),
- "%upx",
- Rec_RECORD_WIDTH);
+ snprintf (StrRecordWidth,sizeof (StrRecordWidth),"%upx",Rec_RECORD_WIDTH);
Box_BoxBegin (StrRecordWidth,Txt_Password,
NULL,NULL,
Hlp_PROFILE_Password,Box_NOT_CLOSABLE);
@@ -833,7 +831,7 @@ void Pwd_ShowFormChgOtherUsrPwd (void)
break;
}
Frm_StartFormAnchor (NextAction,Pwd_PASSWORD_SECTION_ID);
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
/* New password */
HTM_TABLE_BeginWidePadding (2);
diff --git a/swad_photo.c b/swad_photo.c
index 170c3ba5..40717340 100644
--- a/swad_photo.c
+++ b/swad_photo.c
@@ -271,7 +271,7 @@ static void Pho_PutIconToRequestRemoveOtherUsrPhoto (__attribute__((unused)) voi
break;
}
Lay_PutContextualLinkOnlyIcon (NextAction,NULL,
- Usr_PutParamOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,
+ Usr_PutParamOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EnUsrCod,
"trash.svg",
Txt_Remove_photo);
}
@@ -343,7 +343,7 @@ static void Pho_ReqPhoto (const struct UsrData *UsrDat)
break;
}
Frm_StartForm (NextAction);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
}
/***** Show help message *****/
@@ -531,7 +531,7 @@ void Pho_ReqRemoveUsrPhoto (void)
break;
}
Ale_ShowAlertAndButton2 (NextAction,NULL,NULL,
- Usr_PutParamOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,
+ Usr_PutParamOtherUsrCodEncrypted,Gbl.Usrs.Other.UsrDat.EnUsrCod,
Btn_REMOVE_BUTTON,Txt_Remove_photo);
}
else
@@ -614,10 +614,8 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct UsrData *Usr
/***** Creates directories if not exist *****/
Fil_CreateDirIfNotExists (Cfg_PATH_PHOTO_PRIVATE);
- snprintf (PathPhotosPriv,sizeof (PathPhotosPriv),
- "%s/%02u",
- Cfg_PATH_PHOTO_PRIVATE,
- (unsigned) (UsrDat->UsrCod % 100));
+ snprintf (PathPhotosPriv,sizeof (PathPhotosPriv),"%s/%02u",
+ Cfg_PATH_PHOTO_PRIVATE,(unsigned) (UsrDat->UsrCod % 100));
Fil_CreateDirIfNotExists (PathPhotosPriv);
/***** Create directories if not exists
@@ -647,10 +645,8 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct UsrData *Usr
}
/* End the reception of photo in a temporary file */
- snprintf (FileNamePhotoTmp,sizeof (FileNamePhotoTmp),
- "%s/%s.jpg",
- Cfg_PATH_PHOTO_TMP_PUBLIC,
- Gbl.UniqueNameEncrypted);
+ snprintf (FileNamePhotoTmp,sizeof (FileNamePhotoTmp),"%s/%s.jpg",
+ Cfg_PATH_PHOTO_TMP_PUBLIC,Gbl.UniqueNameEncrypted);
if (!Fil_EndReceptionOfFile (FileNamePhotoTmp,Param))
{
Ale_ShowAlert (Ale_ERROR,"Error copying file.");
@@ -659,15 +655,13 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct UsrData *Usr
/* Copy the original photo received to private directory.
The purpose of this copy is only to have a backup used for researching better methods to detect faces in images */
- snprintf (PathRelPhoto,sizeof (PathRelPhoto),
- "%s/%02u/%ld_original.jpg",
+ snprintf (PathRelPhoto,sizeof (PathRelPhoto),"%s/%02u/%ld_original.jpg",
Cfg_PATH_PHOTO_PRIVATE,
(unsigned) (UsrDat->UsrCod % 100),UsrDat->UsrCod);
Fil_FastCopyOfFiles (FileNamePhotoTmp,PathRelPhoto);
/***** Call to program that makes photo processing / face detection *****/
- snprintf (Command,sizeof (Command),
- Cfg_COMMAND_FACE_DETECTION,
+ snprintf (Command,sizeof (Command),Cfg_COMMAND_FACE_DETECTION,
FileNamePhotoTmp);
ReturnCode = system (Command);
if (ReturnCode == -1)
@@ -679,10 +673,8 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct UsrData *Usr
{
case 0: // Faces detected
/***** Open text file with text for image map *****/
- snprintf (FileNameTxtMap,sizeof (FileNameTxtMap),
- "%s/%s_map.txt",
- Cfg_PATH_PHOTO_TMP_PUBLIC,
- Gbl.UniqueNameEncrypted);
+ snprintf (FileNameTxtMap,sizeof (FileNameTxtMap),"%s/%s_map.txt",
+ Cfg_PATH_PHOTO_TMP_PUBLIC,Gbl.UniqueNameEncrypted);
if ((FileTxtMap = fopen (FileNameTxtMap,"rb")) == NULL)
Lay_ShowErrorAndExit ("Can not read text file with coordinates of detected faces.");
@@ -714,7 +706,7 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct UsrData *Usr
break;
}
Frm_StartForm (NextAction);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
}
Par_PutHiddenParamString (NULL,"FileName",StrFileName);
Frm_EndForm ();
@@ -778,9 +770,7 @@ static bool Pho_ReceivePhotoAndDetectFaces (bool ItsMe,const struct UsrData *Usr
if (BackgroundCode == 1)
{
NumFace++;
- snprintf (FormId,sizeof (FormId),
- "form_%d",
- NumLastForm + NumFace);
+ snprintf (FormId,sizeof (FormId),"form_%d",NumLastForm + NumFace);
HTM_TxtF ("\n");
/***** Show map photo *****/
- snprintf (FileNamePhotoMap,sizeof (FileNamePhotoMap),
- "%s/%s_map.jpg",
- Cfg_PATH_PHOTO_TMP_PUBLIC,
- Gbl.UniqueNameEncrypted);
+ snprintf (FileNamePhotoMap,sizeof (FileNamePhotoMap),"%s/%s_map.jpg",
+ Cfg_PATH_PHOTO_TMP_PUBLIC,Gbl.UniqueNameEncrypted);
HTM_DIV_Begin ("class=\"TIT CM\"");
HTM_IMG (Cfg_URL_PHOTO_TMP_PUBLIC,
Str_BuildStringStr ("%s_map.jpg",Gbl.UniqueNameEncrypted),
@@ -870,15 +858,12 @@ static void Pho_UpdatePhoto1 (struct UsrData *UsrDat)
Par_GetParToText ("FileName",Gbl.Usrs.FileNamePhoto,NAME_MAX); // Example of FileNamePhoto: "4924a838630e_016"
/***** Convert the temporary photo resulting of the processing to the current photo of the user *****/
- snprintf (PathPhotoTmp,sizeof (PathPhotoTmp),
- "%s/%s_paso3.jpg",
- Cfg_PATH_PHOTO_TMP_PUBLIC,
- Gbl.Usrs.FileNamePhoto);
+ snprintf (PathPhotoTmp,sizeof (PathPhotoTmp),"%s/%s_paso3.jpg",
+ Cfg_PATH_PHOTO_TMP_PUBLIC,Gbl.Usrs.FileNamePhoto);
if (Fil_CheckIfPathExists (PathPhotoTmp)) // The file with the selected photo exists
{
/* Copy the temporary file of the third (last) step resulting of the processing to the directory of private photos */
- snprintf (PathRelPhoto,sizeof (PathRelPhoto),
- "%s/%02u/%ld.jpg",
+ snprintf (PathRelPhoto,sizeof (PathRelPhoto),"%s/%02u/%ld.jpg",
Cfg_PATH_PHOTO_PRIVATE,
(unsigned) (UsrDat->UsrCod % 100),UsrDat->UsrCod);
Fil_FastCopyOfFiles (PathPhotoTmp,PathRelPhoto);
@@ -1030,13 +1015,11 @@ bool Pho_BuildLinkToPhoto (const struct UsrData *UsrDat,char PhotoURL[PATH_MAX +
if (UsrDat->Photo[0])
{
/***** Make path to public photo *****/
- snprintf (PathPublPhoto,sizeof (PathPublPhoto),
- "%s/%s.jpg",
+ snprintf (PathPublPhoto,sizeof (PathPublPhoto),"%s/%s.jpg",
Cfg_PATH_PHOTO_PUBLIC,UsrDat->Photo);
/***** Make path to private photo from public directory *****/
- snprintf (PathPrivPhoto,sizeof (PathPrivPhoto),
- "%s/%02u/%ld.jpg",
+ snprintf (PathPrivPhoto,sizeof (PathPrivPhoto),"%s/%02u/%ld.jpg",
Cfg_PATH_PHOTO_PRIVATE,
(unsigned) (UsrDat->UsrCod % 100),UsrDat->UsrCod);
@@ -1047,8 +1030,7 @@ bool Pho_BuildLinkToPhoto (const struct UsrData *UsrDat,char PhotoURL[PATH_MAX +
" to access to user's private photo");
/***** Create the public URL of the photo *****/
- snprintf (PhotoURL,PATH_MAX + 1,
- "%s/%s.jpg",
+ snprintf (PhotoURL,PATH_MAX + 1,"%s/%s.jpg",
Cfg_URL_PHOTO_PUBLIC,UsrDat->Photo);
return true;
@@ -1069,10 +1051,8 @@ bool Pho_BuildLinkToPhoto (const struct UsrData *UsrDat,char PhotoURL[PATH_MAX +
bool Pho_CheckIfPrivPhotoExists (long UsrCod,char PathPrivRelPhoto[PATH_MAX + 1])
{
/***** Make path to private photo *****/
- snprintf (PathPrivRelPhoto,PATH_MAX + 1,
- "%s/%02u/%ld.jpg",
- Cfg_PATH_PHOTO_PRIVATE,
- (unsigned) (UsrCod % 100),UsrCod);
+ snprintf (PathPrivRelPhoto,PATH_MAX + 1,"%s/%02u/%ld.jpg",
+ Cfg_PATH_PHOTO_PRIVATE,(unsigned) (UsrCod % 100),UsrCod);
return Fil_CheckIfPathExists (PathPrivRelPhoto);
}
@@ -1095,16 +1075,14 @@ bool Pho_RemovePhoto (struct UsrData *UsrDat)
Pho_ClearPhotoName (UsrDat->UsrCod);
/***** Remove public link *****/
- snprintf (PathPublPhoto,sizeof (PathPublPhoto),
- "%s/%s.jpg",
+ snprintf (PathPublPhoto,sizeof (PathPublPhoto),"%s/%s.jpg",
Cfg_PATH_PHOTO_PUBLIC,UsrDat->Photo);
if (Fil_CheckIfPathExists (PathPublPhoto)) // Public link exists
if (unlink (PathPublPhoto)) // Remove public link
NumErrors++;
/***** Remove photo *****/
- snprintf (PathPrivRelPhoto,sizeof (PathPrivRelPhoto),
- "%s/%02u/%ld.jpg",
+ snprintf (PathPrivRelPhoto,sizeof (PathPrivRelPhoto),"%s/%02u/%ld.jpg",
Cfg_PATH_PHOTO_PRIVATE,
(unsigned) (UsrDat->UsrCod % 100),UsrDat->UsrCod);
if (Fil_CheckIfPathExists (PathPrivRelPhoto)) // Photo exists
@@ -1115,7 +1093,7 @@ bool Pho_RemovePhoto (struct UsrData *UsrDat)
/***** Remove original photo *****/
snprintf (PathPrivRelPhoto,sizeof (PathPrivRelPhoto),
- "%s/%02u/%ld_original.jpg",
+ "%s/%02u/%ld_original.jpg",
Cfg_PATH_PHOTO_PRIVATE,
(unsigned) (UsrDat->UsrCod % 100),UsrDat->UsrCod);
if (Fil_CheckIfPathExists (PathPrivRelPhoto)) // Original photo exists
@@ -1166,14 +1144,12 @@ void Pho_UpdatePhotoName (struct UsrData *UsrDat)
Gbl.UniqueNameEncrypted,UsrDat->UsrCod);
/***** Remove the old symbolic link to photo *****/
- snprintf (PathPublPhoto,sizeof (PathPublPhoto),
- "%s/%s.jpg",
+ snprintf (PathPublPhoto,sizeof (PathPublPhoto),"%s/%s.jpg",
Cfg_PATH_PHOTO_PUBLIC,UsrDat->Photo);
unlink (PathPublPhoto); // Remove public link
/***** Update photo name in user's data *****/
- Str_Copy (UsrDat->Photo,Gbl.UniqueNameEncrypted,
- Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
+ Str_Copy (UsrDat->Photo,Gbl.UniqueNameEncrypted,sizeof (UsrDat->Photo) - 1);
}
/*****************************************************************************/
@@ -1209,7 +1185,7 @@ void Pho_ShowUsrPhoto (const struct UsrData *UsrDat,const char *PhotoURL,
Frm_StartFormUnique (ActSeeOthPubPrf);
else
Frm_StartForm (ActSeeOthPubPrf);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_BUTTON_SUBMIT_Begin (NULL,"BT_LINK",NULL);
}
@@ -1368,8 +1344,7 @@ void Pho_CalcPhotoDegree (void)
TypeOfAverage++)
{
snprintf (DirAvgPhotosRelPath[TypeOfAverage],
- sizeof (DirAvgPhotosRelPath[TypeOfAverage]),
- "%s/%s",
+ sizeof (DirAvgPhotosRelPath[TypeOfAverage]),"%s/%s",
Cfg_PATH_PHOTO_PUBLIC,Pho_StrAvgPhotoDirs[TypeOfAverage]);
Fil_CreateDirIfNotExists (DirAvgPhotosRelPath[TypeOfAverage]);
}
@@ -1656,8 +1631,7 @@ static void Pho_ComputeAveragePhoto (long DegCod,Usr_Sex_t Sex,Rol_Role_t Role,
/***** Call to program to calculate average photo *****/
if (*NumStdsWithPhoto)
{
- snprintf (StrCallToProgram,sizeof (StrCallToProgram),
- "%s %s %s",
+ snprintf (StrCallToProgram,sizeof (StrCallToProgram),"%s %s %s",
Pho_StrAvgPhotoPrograms[TypeOfAverage],
FileNamePhotoNames,PathRelAvgPhoto);
ReturnCode = system (StrCallToProgram);
@@ -2058,7 +2032,7 @@ static void Pho_PutLinkToCalculateDegreeStats (const struct Pho_DegPhotos *DegPh
EstimatedTimeToComputeAvgPhotoInMicroseconds = Pho_GetTimeToComputeAvgPhoto (Degs.Lst[NumDeg].DegCod);
if (EstimatedTimeToComputeAvgPhotoInMicroseconds == -1L)
Str_Copy (StrEstimatedTimeToComputeAvgPhoto,Txt_unknown_TIME,
- Dat_MAX_BYTES_TIME);
+ sizeof (StrEstimatedTimeToComputeAvgPhoto) - 1);
else
Sta_WriteTime (StrEstimatedTimeToComputeAvgPhoto,
EstimatedTimeToComputeAvgPhotoInMicroseconds);
@@ -2502,15 +2476,13 @@ static void Pho_ShowDegreeAvgPhotoAndStat (const struct Deg_Degree *Deg,
if (ShowDegPhoto)
{
- snprintf (PathRelAvgPhoto,sizeof (PathRelAvgPhoto),
- "%s/%s/%ld_%s.jpg",
+ snprintf (PathRelAvgPhoto,sizeof (PathRelAvgPhoto),"%s/%s/%ld_%s.jpg",
Cfg_PATH_PHOTO_PUBLIC,
Pho_StrAvgPhotoDirs[DegPhotos->TypeOfAverage],
Deg->DegCod,Usr_StringsSexDB[Sex]);
if (Fil_CheckIfPathExists (PathRelAvgPhoto))
{
- snprintf (PhotoURL,sizeof (PhotoURL),
- "%s/%s/%ld_%s.jpg",
+ snprintf (PhotoURL,sizeof (PhotoURL),"%s/%s/%ld_%s.jpg",
Cfg_URL_PHOTO_PUBLIC,
Pho_StrAvgPhotoDirs[DegPhotos->TypeOfAverage],
Deg->DegCod,Usr_StringsSexDB[Sex]);
diff --git a/swad_place.c b/swad_place.c
index 47dc080b..4a79ba95 100644
--- a/swad_place.c
+++ b/swad_place.c
@@ -397,8 +397,8 @@ void Plc_GetListPlaces (struct Plc_Places *Places)
Places->Num = (unsigned) NumRows;
/***** Create list with courses in centre *****/
- if ((Places->Lst = (struct Plc_Place *) calloc (NumRows,sizeof (struct Plc_Place))) == NULL)
- Lay_NotEnoughMemoryExit ();
+ if ((Places->Lst = calloc (NumRows,sizeof (*Places->Lst))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/***** Get the places *****/
for (NumPlc = 0;
@@ -414,13 +414,9 @@ void Plc_GetListPlaces (struct Plc_Places *Places)
if ((Plc->PlcCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of place.");
- /* Get the short name of the place (row[1]) */
- Str_Copy (Plc->ShrtName,row[1],
- Plc_MAX_BYTES_PLACE_SHRT_NAME);
-
- /* Get the full name of the place (row[2]) */
- Str_Copy (Plc->FullName,row[2],
- Plc_MAX_BYTES_PLACE_FULL_NAME);
+ /* Get the short (row[1]) and full (row[2]) names of the place */
+ Str_Copy (Plc->ShrtName,row[1],sizeof (Plc->ShrtName) - 1);
+ Str_Copy (Plc->FullName,row[2],sizeof (Plc->FullName) - 1);
/* Get number of centres in this place (row[3]) */
if (sscanf (row[3],"%u",&Plc->NumCtrs) != 1)
@@ -454,17 +450,13 @@ void Plc_GetDataOfPlaceByCod (struct Plc_Place *Plc)
/***** Check if place code is correct *****/
if (Plc->PlcCod < 0)
{
- Str_Copy (Plc->ShrtName,Txt_Place_unspecified,
- Plc_MAX_BYTES_PLACE_SHRT_NAME);
- Str_Copy (Plc->FullName,Txt_Place_unspecified,
- Plc_MAX_BYTES_PLACE_FULL_NAME);
+ Str_Copy (Plc->ShrtName,Txt_Place_unspecified,sizeof (Plc->ShrtName) - 1);
+ Str_Copy (Plc->FullName,Txt_Place_unspecified,sizeof (Plc->FullName) - 1);
}
else if (Plc->PlcCod == 0)
{
- Str_Copy (Plc->ShrtName,Txt_Another_place,
- Plc_MAX_BYTES_PLACE_SHRT_NAME);
- Str_Copy (Plc->FullName,Txt_Another_place,
- Plc_MAX_BYTES_PLACE_FULL_NAME);
+ Str_Copy (Plc->ShrtName,Txt_Another_place,sizeof (Plc->ShrtName) - 1);
+ Str_Copy (Plc->FullName,Txt_Another_place,sizeof (Plc->FullName) - 1);
}
else if (Plc->PlcCod > 0)
{
@@ -496,13 +488,9 @@ void Plc_GetDataOfPlaceByCod (struct Plc_Place *Plc)
/* Get row */
row = mysql_fetch_row (mysql_res);
- /* Get the short name of the place (row[0]) */
- Str_Copy (Plc->ShrtName,row[0],
- Plc_MAX_BYTES_PLACE_SHRT_NAME);
-
- /* Get the full name of the place (row[1]) */
- Str_Copy (Plc->FullName,row[1],
- Plc_MAX_BYTES_PLACE_FULL_NAME);
+ /* Get the short (row[0]) and full (row[1]) names of the place */
+ Str_Copy (Plc->ShrtName,row[0],sizeof (Plc->ShrtName) - 1);
+ Str_Copy (Plc->FullName,row[1],sizeof (Plc->FullName) - 1);
/* Get number of centres in this place (row[2]) */
if (sscanf (row[2],"%u",&Plc->NumCtrs) != 1)
@@ -754,8 +742,7 @@ static void Plc_RenamePlace (Cns_ShrtOrFullName_t ShrtOrFullName)
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
/***** Update place name *****/
- Str_Copy (CurrentPlcName,NewPlcName,
- MaxBytes);
+ Str_Copy (CurrentPlcName,NewPlcName,MaxBytes);
}
/*****************************************************************************/
@@ -952,8 +939,8 @@ static void Plc_EditingPlaceConstructor (void)
Lay_ShowErrorAndExit ("Error initializing place.");
/***** Allocate memory for place *****/
- if ((Plc_EditingPlc = (struct Plc_Place *) malloc (sizeof (struct Plc_Place))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for place.");
+ if ((Plc_EditingPlc = malloc (sizeof (*Plc_EditingPlc))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/***** Reset place *****/
Plc_EditingPlc->PlcCod = -1L;
diff --git a/swad_plugin.c b/swad_plugin.c
index f06bb6f5..c261c497 100644
--- a/swad_plugin.c
+++ b/swad_plugin.c
@@ -131,9 +131,7 @@ void Plg_ListPlugins (void)
{
Plg = &(Gbl.Plugins.Lst[NumPlg]);
- snprintf (URL,sizeof (URL),
- "%s%s",
- Plg->URL,Gbl.Session.Id);
+ snprintf (URL,sizeof (URL),"%s%s",Plg->URL,Gbl.Session.Id);
/* Plugin logo */
// TODO: Change plugin icons to 32x32
@@ -242,7 +240,8 @@ static void Plg_GetListPlugins (void)
Gbl.Plugins.Num = (unsigned) NumRows;
/***** Create list with plugins *****/
- if ((Gbl.Plugins.Lst = (struct Plugin *) calloc ((size_t) Gbl.Plugins.Num,sizeof (struct Plugin))) == NULL)
+ if ((Gbl.Plugins.Lst = calloc (Gbl.Plugins.Num,
+ sizeof (*Gbl.Plugins.Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the plugins *****/
@@ -259,29 +258,14 @@ static void Plg_GetListPlugins (void)
if ((Plg->PlgCod = Str_ConvertStrCodToLongCod (row[0])) < 0)
Lay_ShowErrorAndExit ("Wrong code of plugin.");
- /* Get the name of the plugin (row[1]) */
- Str_Copy (Plg->Name,row[1],
- Plg_MAX_BYTES_PLUGIN_NAME);
-
- /* Get the description of the plugin (row[2]) */
- Str_Copy (Plg->Description,row[2],
- Plg_MAX_BYTES_PLUGIN_DESCRIPTION);
-
- /* Get the logo of the plugin (row[3]) */
- Str_Copy (Plg->Logo,row[3],
- Plg_MAX_BYTES_PLUGIN_LOGO);
-
- /* Get the application key of the plugin (row[4]) */
- Str_Copy (Plg->AppKey,row[4],
- Plg_MAX_BYTES_PLUGIN_APP_KEY);
-
- /* Get the URL of the plugin (row[5]) */
- Str_Copy (Plg->URL,row[5],
- Cns_MAX_BYTES_WWW);
-
- /* Get the IP of the plugin (row[6]) */
- Str_Copy (Plg->IP,row[6],
- Cns_MAX_BYTES_IP);
+ /* Get name (row[1]), description (row[2), logo (row[3]),
+ * application key (row[4]), URL (row[5]) and IP (row[6]) of the plugin */
+ Str_Copy (Plg->Name ,row[1],sizeof (Plg->Name ) - 1);
+ Str_Copy (Plg->Description,row[2],sizeof (Plg->Description) - 1);
+ Str_Copy (Plg->Logo ,row[3],sizeof (Plg->Logo ) - 1);
+ Str_Copy (Plg->AppKey ,row[4],sizeof (Plg->AppKey ) - 1);
+ Str_Copy (Plg->URL ,row[5],sizeof (Plg->URL ) - 1);
+ Str_Copy (Plg->IP ,row[6],sizeof (Plg->IP ) - 1);
}
}
else
@@ -329,29 +313,14 @@ bool Plg_GetDataOfPluginByCod (struct Plugin *Plg)
/* Get row */
row = mysql_fetch_row (mysql_res);
- /* Get the name of the plugin (row[0]) */
- Str_Copy (Plg->Name,row[0],
- Plg_MAX_BYTES_PLUGIN_NAME);
-
- /* Get the description of the plugin (row[1]) */
- Str_Copy (Plg->Description,row[1],
- Plg_MAX_BYTES_PLUGIN_DESCRIPTION);
-
- /* Get the logo of the plugin (row[2]) */
- Str_Copy (Plg->Logo,row[2],
- Plg_MAX_BYTES_PLUGIN_LOGO);
-
- /* Get the application key of the plugin (row[3]) */
- Str_Copy (Plg->AppKey,row[3],
- Plg_MAX_BYTES_PLUGIN_APP_KEY);
-
- /* Get the URL of the plugin (row[4]) */
- Str_Copy (Plg->URL,row[4],
- Cns_MAX_BYTES_WWW);
-
- /* Get the IP of the plugin (row[5]) */
- Str_Copy (Plg->IP,row[5],
- Cns_MAX_BYTES_IP);
+ /* Get name (row[0]), description (row[1]), logo (row[2]),
+ application key (row[3]), URL (row[4]) and IP (row[5]) of the plugin */
+ Str_Copy (Plg->Name ,row[0],sizeof (Plg->Name ) - 1);
+ Str_Copy (Plg->Description,row[1],sizeof (Plg->Description) - 1);
+ Str_Copy (Plg->Logo ,row[2],sizeof (Plg->Logo ) - 1);
+ Str_Copy (Plg->AppKey ,row[3],sizeof (Plg->AppKey ) - 1);
+ Str_Copy (Plg->URL ,row[4],sizeof (Plg->URL ) - 1);
+ Str_Copy (Plg->IP ,row[5],sizeof (Plg->IP ) - 1);
}
else
PluginFound = false;
@@ -595,8 +564,7 @@ void Plg_RenamePlugin (void)
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
/***** Update name *****/
- Str_Copy (Plg_EditingPlg->Name,NewPlgName,
- Plg_MAX_BYTES_PLUGIN_NAME);
+ Str_Copy (Plg_EditingPlg->Name,NewPlgName,sizeof (Plg_EditingPlg->Name) - 1);
}
/*****************************************************************************/
@@ -654,7 +622,7 @@ void Plg_ChangePlgDescription (void)
/***** Update description *****/
Str_Copy (Plg_EditingPlg->Description,NewDescription,
- Plg_MAX_BYTES_PLUGIN_DESCRIPTION);
+ sizeof (Plg_EditingPlg->Description) - 1);
}
/*****************************************************************************/
@@ -697,8 +665,7 @@ void Plg_ChangePlgLogo (void)
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
/***** Update logo *****/
- Str_Copy (Plg_EditingPlg->Logo,NewLogo,
- Plg_MAX_BYTES_PLUGIN_LOGO);
+ Str_Copy (Plg_EditingPlg->Logo,NewLogo,sizeof (Plg_EditingPlg->Logo) - 1);
}
/*****************************************************************************/
@@ -742,7 +709,7 @@ void Plg_ChangePlgAppKey (void)
/***** Update app key *****/
Str_Copy (Plg_EditingPlg->AppKey,NewAppKey,
- Plg_MAX_BYTES_PLUGIN_APP_KEY);
+ sizeof (Plg_EditingPlg->AppKey) - 1);
}
/*****************************************************************************/
@@ -785,8 +752,7 @@ void Plg_ChangePlgURL (void)
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
/***** Update URL *****/
- Str_Copy (Plg_EditingPlg->URL,NewURL,
- Cns_MAX_BYTES_WWW);
+ Str_Copy (Plg_EditingPlg->URL,NewURL,sizeof (Plg_EditingPlg->URL) - 1);
}
/*****************************************************************************/
@@ -829,8 +795,7 @@ void Plg_ChangePlgIP (void)
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
/***** Update IP *****/
- Str_Copy (Plg_EditingPlg->IP,NewIP,
- Cns_MAX_BYTES_IP);
+ Str_Copy (Plg_EditingPlg->IP,NewIP,sizeof (Plg_EditingPlg->IP) - 1);
}
/*****************************************************************************/
@@ -1059,8 +1024,8 @@ static void Plg_EditingPluginConstructor (void)
Lay_ShowErrorAndExit ("Error initializing plugin.");
/***** Allocate memory for plugin *****/
- if ((Plg_EditingPlg = (struct Plugin *) malloc (sizeof (struct Plugin))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for plugin.");
+ if ((Plg_EditingPlg = malloc (sizeof (*Plg_EditingPlg))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/***** Reset plugin *****/
Plg_EditingPlg->PlgCod = -1L;
diff --git a/swad_profile.c b/swad_profile.c
index c0a3fdb4..309a2b48 100644
--- a/swad_profile.c
+++ b/swad_profile.c
@@ -139,16 +139,14 @@ void Prf_SeeSocialProfiles (void)
/*****************************************************************************/
char *Prf_GetURLPublicProfile (char URL[Cns_MAX_BYTES_WWW + 1],
- const char *NicknameWithoutArroba)
+ const char *NickWithoutArroba)
{
extern const char *Lan_STR_LANG_ID[1 + Lan_NUM_LANGUAGES];
/***** Build URL using nickname *****/
- snprintf (URL,Cns_MAX_BYTES_WWW + 1,
- "%s/%s?usr=@%s",
- Cfg_URL_SWAD_CGI,
- Lan_STR_LANG_ID[Gbl.Prefs.Language],
- NicknameWithoutArroba);
+ snprintf (URL,Cns_MAX_BYTES_WWW + 1,"%s/%s?usr=@%s",
+ Cfg_URL_SWAD_CGI,Lan_STR_LANG_ID[Gbl.Prefs.Language],
+ NickWithoutArroba);
return URL;
}
@@ -162,7 +160,7 @@ void Prf_PutLinkMyPublicProfile (void)
extern const char *Txt_My_public_profile;
Lay_PutContextualLinkIconText (ActSeeOthPubPrf,NULL,
- Usr_PutParamMyUsrCodEncrypted,Gbl.Usrs.Me.UsrDat.EncryptedUsrCod,
+ Usr_PutParamMyUsrCodEncrypted,Gbl.Usrs.Me.UsrDat.EnUsrCod,
"user-circle.svg",
Txt_My_public_profile);
}
@@ -192,7 +190,7 @@ void Prf_RequestUserProfile (void)
extern const char *The_ClassFormInBox[The_NUM_THEMES];
extern const char *Txt_Nickname;
extern const char *Txt_Continue;
- char NicknameWithArroba[1 + Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA + 1];
+ char NickWithArroba[1 + Nck_MAX_BYTES_NICKNAME_WITHOUT_ARROBA + 1];
if (Gbl.Usrs.Me.Logged)
{
@@ -217,10 +215,9 @@ void Prf_RequestUserProfile (void)
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
HTM_TxtColonNBSP (Txt_Nickname);
- snprintf (NicknameWithArroba,sizeof (NicknameWithArroba),
- "@%s",
+ snprintf (NickWithArroba,sizeof (NickWithArroba),"@%s",
Gbl.Usrs.Me.UsrDat.Nickname);
- HTM_INPUT_TEXT ("usr",Nck_MAX_BYTES_NICKNAME_FROM_FORM,NicknameWithArroba,
+ HTM_INPUT_TEXT ("usr",Nck_MAX_BYTES_NICKNAME_FROM_FORM,NickWithArroba,
HTM_DONT_SUBMIT_ON_CHANGE,
"size=\"18\"");
HTM_LABEL_End ();
@@ -522,7 +519,7 @@ static void Prf_ShowTimeSinceFirstClick (const struct UsrData *UsrDat,
}
else // First click time is unknown or user never logged
/***** Button to fetch and store user's figures *****/
- Prf_PutLinkCalculateFigures (UsrDat->EncryptedUsrCod);
+ Prf_PutLinkCalculateFigures (UsrDat->EnUsrCod);
Prf_EndListItem ();
}
@@ -625,7 +622,7 @@ static void Prf_ShowNumClicks (const struct UsrData *UsrDat,
}
else // Number of clicks is unknown
/***** Button to fetch and store user's figures *****/
- Prf_PutLinkCalculateFigures (UsrDat->EncryptedUsrCod);
+ Prf_PutLinkCalculateFigures (UsrDat->EnUsrCod);
Prf_EndListItem ();
}
@@ -662,7 +659,7 @@ static void Prf_ShowNumFileViews (const struct UsrData *UsrDat,
}
else // Number of file views is unknown
/***** Button to fetch and store user's figures *****/
- Prf_PutLinkCalculateFigures (UsrDat->EncryptedUsrCod);
+ Prf_PutLinkCalculateFigures (UsrDat->EnUsrCod);
Prf_EndListItem ();
}
@@ -699,7 +696,7 @@ static void Prf_ShowNumSocialPublications (const struct UsrData *UsrDat,
}
else // Number of social publications is unknown
/***** Button to fetch and store user's figures *****/
- Prf_PutLinkCalculateFigures (UsrDat->EncryptedUsrCod);
+ Prf_PutLinkCalculateFigures (UsrDat->EnUsrCod);
Prf_EndListItem ();
}
@@ -736,7 +733,7 @@ static void Prf_ShowNumForumPosts (const struct UsrData *UsrDat,
}
else // Number of forum posts is unknown
/***** Button to fetch and store user's figures *****/
- Prf_PutLinkCalculateFigures (UsrDat->EncryptedUsrCod);
+ Prf_PutLinkCalculateFigures (UsrDat->EnUsrCod);
Prf_EndListItem ();
}
@@ -773,7 +770,7 @@ static void Prf_ShowNumMessagesSent (const struct UsrData *UsrDat,
}
else // Number of messages sent is unknown
/***** Button to fetch and store user's figures *****/
- Prf_PutLinkCalculateFigures (UsrDat->EncryptedUsrCod);
+ Prf_PutLinkCalculateFigures (UsrDat->EnUsrCod);
Prf_EndListItem ();
}
@@ -1272,8 +1269,7 @@ static void Prf_CreateUsrFigures (long UsrCod,const struct UsrFigures *UsrFigure
if (CreatingMyOwnAccount)
// This is the first click
- Str_Copy (SubQueryFirstClickTime,"NOW()",
- Prf_MAX_BYTES_SUBQUERY_FIRST_CLICK_TIME);
+ Str_Copy (SubQueryFirstClickTime,"NOW()",sizeof (SubQueryFirstClickTime) - 1);
else
sprintf (SubQueryFirstClickTime,"FROM_UNIXTIME(%ld)",
(long) UsrFigures->FirstClickTimeUTC); // 0 ==> unknown first click time or user never logged
@@ -1788,7 +1784,7 @@ static void Prf_ShowUsrInRanking (struct UsrData *UsrDat,unsigned Rank,bool ItsM
if (Visible)
{
Frm_StartForm (ActSeeOthPubPrf);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_BUTTON_SUBMIT_Begin (Txt_Another_user_s_profile,
ItsMe ? "BT_LINK RANK_USR DAT_SMALL_N" :
"BT_LINK RANK_USR DAT_SMALL",
diff --git a/swad_profile.h b/swad_profile.h
index 80599072..61f29649 100644
--- a/swad_profile.h
+++ b/swad_profile.h
@@ -53,7 +53,7 @@ struct UsrFigures
void Prf_SeeSocialProfiles (void);
char *Prf_GetURLPublicProfile (char URL[Cns_MAX_BYTES_WWW + 1],
- const char *NicknameWithoutArroba);
+ const char *NickWithoutArroba);
void Prf_PutLinkMyPublicProfile (void);
void Prf_PutLinkRequestAnotherUserProfile (void);
void Prf_RequestUserProfile (void);
diff --git a/swad_program.c b/swad_program.c
index d4ac9610..a8e7a4e9 100644
--- a/swad_program.c
+++ b/swad_program.c
@@ -666,8 +666,8 @@ static void Prg_CreateLevels (void)
4 1
5 0 <--- Used to create a new item
*/
- if ((Prg_Gbl.Levels = (struct Level *) calloc ((size_t) (1 + MaxLevel + 1),
- sizeof (struct Level))) == NULL)
+ if ((Prg_Gbl.Levels = calloc (1 + MaxLevel + 1,
+ sizeof (*Prg_Gbl.Levels))) == NULL)
Lay_NotEnoughMemoryExit ();
}
else
@@ -778,9 +778,7 @@ static void Prg_PutFormsToRemEditOneItem (unsigned NumItem,
char StrItemIndex[Cns_MAX_DECIMAL_DIGITS_UINT + 1];
/***** Initialize item index string *****/
- snprintf (StrItemIndex,sizeof (StrItemIndex),
- "%u",
- Item->Hierarchy.Index);
+ snprintf (StrItemIndex,sizeof (StrItemIndex),"%u",Item->Hierarchy.Index);
switch (Gbl.Usrs.Me.Role.Logged)
{
@@ -992,9 +990,8 @@ static void Prg_GetListItems (void)
if (Prg_Gbl.List.NumItems) // Items found...
{
/***** Create list of program items *****/
- if ((Prg_Gbl.List.Items =
- (struct ProgramItemHierarchy *) calloc ((size_t) Prg_Gbl.List.NumItems,
- sizeof (struct ProgramItemHierarchy))) == NULL)
+ if ((Prg_Gbl.List.Items = calloc (Prg_Gbl.List.NumItems,
+ sizeof (*Prg_Gbl.List.Items))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the program items codes *****/
@@ -1116,8 +1113,7 @@ static void Prg_GetDataOfItem (struct ProgramItem *Item,
Item->Open = (row[7][0] == '1');
/* Get the title of the program item (row[8]) */
- Str_Copy (Item->Title,row[8],
- Prg_MAX_BYTES_PROGRAM_ITEM_TITLE);
+ Str_Copy (Item->Title,row[8],sizeof (Item->Title) - 1);
}
/***** Free structure that stores the query result *****/
@@ -1179,8 +1175,7 @@ static void Prg_GetItemTxtFromDB (long ItmCod,char Txt[Cns_MAX_BYTES_TEXT + 1])
{
/* Get info text */
row = mysql_fetch_row (mysql_res);
- Str_Copy (Txt,row[0],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Txt,row[0],Cns_MAX_BYTES_TEXT);
}
else
Txt[0] = '\0';
diff --git a/swad_project.c b/swad_project.c
index 712a5488..0a81e7ad 100644
--- a/swad_project.c
+++ b/swad_project.c
@@ -814,7 +814,7 @@ void Prj_PutParams (struct Prj_Filter *Filter,
/***** Put another user's code *****/
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
/***** Put selected users' codes *****/
if (Filter->Who == Usr_WHO_SELECTED)
@@ -2236,7 +2236,7 @@ static void Prj_ShowTableAllProjectsMembersWithARole (const struct Prj_Project *
HTM_Txt (Gbl.Usrs.Other.UsrDat.Surname1);
if (Gbl.Usrs.Other.UsrDat.Surname2[0])
HTM_TxtF (" %s",Gbl.Usrs.Other.UsrDat.Surname2);
- HTM_TxtF (", %s",Gbl.Usrs.Other.UsrDat.FirstName);
+ HTM_TxtF (", %s",Gbl.Usrs.Other.UsrDat.FrstName);
HTM_LI_End ();
}
}
@@ -2506,7 +2506,7 @@ static void Prj_AddUsrsToProject (Prj_RoleInProject_t RoleInProject)
while (*Ptr)
{
/* Get next user */
- Par_GetNextStrUntilSeparParamMult (&Ptr,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,Gbl.Usrs.Other.UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Other.UsrDat);
@@ -3072,7 +3072,8 @@ static void Prj_GetListProjects (struct Prj_Projects *Projects)
NumPrjsFromDB = (unsigned) NumRows;
/***** Create list of projects *****/
- if ((Projects->LstPrjCods = (long *) calloc (NumRows,sizeof (long))) == NULL)
+ if ((Projects->LstPrjCods = calloc (NumRows,
+ sizeof (*Projects->LstPrjCods))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the projects codes *****/
@@ -3226,25 +3227,13 @@ void Prj_GetDataOfProjectByCod (struct Prj_Project *Prj)
/* Get modification date/time (row[9] holds the modification UTC time) */
Prj->ModifTime = Dat_GetUNIXTimeFromStr (row[9]);
- /* Get the title of the project (row[10]) */
- Str_Copy (Prj->Title,row[10],
- Prj_MAX_BYTES_PROJECT_TITLE);
-
- /* Get the description of the project (row[11]) */
- Str_Copy (Prj->Description,row[11],
- Cns_MAX_BYTES_TEXT);
-
- /* Get the required knowledge for the project (row[12]) */
- Str_Copy (Prj->Knowledge,row[12],
- Cns_MAX_BYTES_TEXT);
-
- /* Get the required materials for the project (row[13]) */
- Str_Copy (Prj->Materials,row[13],
- Cns_MAX_BYTES_TEXT);
-
- /* Get the URL of the project (row[14]) */
- Str_Copy (Prj->URL,row[14],
- Cns_MAX_BYTES_WWW);
+ /* Get title (row[10]), description (row[11]), required knowledge (row[12]),
+ required materials (row[13]) and URL (row[14]) of the project */
+ Str_Copy (Prj->Title ,row[10],sizeof (Prj->Title ) - 1);
+ Str_Copy (Prj->Description,row[11],Cns_MAX_BYTES_TEXT);
+ Str_Copy (Prj->Knowledge ,row[12],Cns_MAX_BYTES_TEXT);
+ Str_Copy (Prj->Materials ,row[13],Cns_MAX_BYTES_TEXT);
+ Str_Copy (Prj->URL ,row[14],sizeof (Prj->URL ) - 1);
}
/***** Free structure that stores the query result *****/
@@ -3409,8 +3398,7 @@ void Prj_RemoveProject (void)
Brw_RemovePrjFilesFromDB (Prj.PrjCod);
/***** Remove directory of the project *****/
- snprintf (PathRelPrj,sizeof (PathRelPrj),
- "%s/%ld/%s/%02u/%ld",
+ snprintf (PathRelPrj,sizeof (PathRelPrj),"%s/%ld/%s/%02u/%ld",
Cfg_PATH_CRS_PRIVATE,Prj.CrsCod,Cfg_FOLDER_PRJ,
(unsigned) (Prj.PrjCod % 100),Prj.PrjCod);
Fil_RemoveTree (PathRelPrj);
@@ -3815,13 +3803,13 @@ static void Prj_EditOneProjectTxtArea (const char *Id,
void Prj_AllocMemProject (struct Prj_Project *Prj)
{
- if ((Prj->Description = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
+ if ((Prj->Description = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
- if ((Prj->Knowledge = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
+ if ((Prj->Knowledge = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
- if ((Prj->Materials = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
+ if ((Prj->Materials = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
}
diff --git a/swad_record.c b/swad_record.c
index 644c3026..574a1993 100644
--- a/swad_record.c
+++ b/swad_record.c
@@ -212,7 +212,8 @@ void Rec_GetListRecordFieldsInCurrentCrs (void)
if (Gbl.Crs.Records.LstFields.Num)
{
/***** Create a list of fields *****/
- if ((Gbl.Crs.Records.LstFields.Lst = (struct RecordField *) calloc (Gbl.Crs.Records.LstFields.Num,sizeof (struct RecordField))) == NULL)
+ if ((Gbl.Crs.Records.LstFields.Lst = calloc (Gbl.Crs.Records.LstFields.Num,
+ sizeof (*Gbl.Crs.Records.LstFields.Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the fields *****/
@@ -229,7 +230,7 @@ void Rec_GetListRecordFieldsInCurrentCrs (void)
/* Name of the field (row[1]) */
Str_Copy (Gbl.Crs.Records.LstFields.Lst[NumRow].Name,row[1],
- Rec_MAX_BYTES_NAME_FIELD);
+ sizeof (Gbl.Crs.Records.LstFields.Lst[NumRow].Name) - 1);
/* Number of lines (row[2]) */
Gbl.Crs.Records.LstFields.Lst[NumRow].NumLines = Rec_ConvertToNumLinesField (row[2]);
@@ -291,8 +292,7 @@ void Rec_ListFieldsRecordsForEdition (void)
HTM_TD_Begin ("class=\"CM\"");
Frm_StartForm (ActChgRowFie);
Rec_PutParamFieldCod (&Gbl.Crs.Records.LstFields.Lst[NumField].FieldCod);
- snprintf (StrNumLines,sizeof (StrNumLines),
- "%u",
+ snprintf (StrNumLines,sizeof (StrNumLines),"%u",
Gbl.Crs.Records.LstFields.Lst[NumField].NumLines);
HTM_INPUT_TEXT ("NumLines",Cns_MAX_DECIMAL_DIGITS_UINT,StrNumLines,
HTM_SUBMIT_ON_CHANGE,
@@ -362,8 +362,7 @@ void Rec_ShowFormCreateRecordField (void)
/***** Number of lines in form ******/
HTM_TD_Begin ("class=\"CM\"");
- snprintf (StrNumLines,sizeof (StrNumLines),
- "%u",
+ snprintf (StrNumLines,sizeof (StrNumLines),"%u",
Gbl.Crs.Records.Field.NumLines);
HTM_INPUT_TEXT ("NumLines",Cns_MAX_DECIMAL_DIGITS_UINT,StrNumLines,
HTM_DONT_SUBMIT_ON_CHANGE,
@@ -692,8 +691,7 @@ static void Rec_GetFieldByCod (long FieldCod,char Name[Rec_MAX_BYTES_NAME_FIELD
row = mysql_fetch_row (mysql_res);
/* Name of the field */
- Str_Copy (Name,row[0],
- Rec_MAX_BYTES_NAME_FIELD);
+ Str_Copy (Name,row[0],Rec_MAX_BYTES_NAME_FIELD);
/* Number of lines of the field (row[1]) */
*NumLines = Rec_ConvertToNumLinesField (row[1]);
@@ -782,7 +780,7 @@ void Rec_RenameField (void)
/***** Show the form again *****/
Str_Copy (Gbl.Crs.Records.Field.Name,NewFieldName,
- Rec_MAX_BYTES_NAME_FIELD);
+ sizeof (Gbl.Crs.Records.Field.Name) - 1);
Rec_ReqEditRecordFields ();
}
@@ -971,15 +969,13 @@ static void Rec_ListRecordsGsts (Rec_SharedRecordViewType_t TypeOfView)
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS)) // Get from the database the data of the student
{
/* Start container for this user */
- snprintf (RecordSectionId,sizeof (RecordSectionId),
- "record_%u",
- NumUsr);
+ snprintf (RecordSectionId,sizeof (RecordSectionId),"record_%u",NumUsr);
HTM_SECTION_Begin (RecordSectionId);
if (Gbl.Action.Act == ActPrnRecSevGst &&
@@ -1171,7 +1167,7 @@ static void Rec_ListRecordsStds (Rec_SharedRecordViewType_t ShaTypeOfView,
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS)) // Get from the database the data of the student
@@ -1182,9 +1178,7 @@ static void Rec_ListRecordsStds (Rec_SharedRecordViewType_t ShaTypeOfView,
UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&UsrDat);
/* Start container for this user */
- snprintf (RecordSectionId,sizeof (RecordSectionId),
- "record_%u",
- NumUsr);
+ snprintf (RecordSectionId,sizeof (RecordSectionId),"record_%u",NumUsr);
HTM_SECTION_Begin (RecordSectionId);
if (Gbl.Action.Act == ActPrnRecSevStd &&
@@ -1265,9 +1259,7 @@ static void Rec_ShowRecordOneTchCrs (void)
bool ShowOfficeHours;
/***** Width for office hours *****/
- snprintf (Width,sizeof (Width),
- "%upx",
- Rec_RECORD_WIDTH);
+ snprintf (Width,sizeof (Width),"%upx",Rec_RECORD_WIDTH);
/***** Get if teacher has accepted enrolment in current course *****/
Gbl.Usrs.Other.UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&Gbl.Usrs.Other.UsrDat);
@@ -1354,9 +1346,7 @@ static void Rec_ListRecordsTchs (Rec_SharedRecordViewType_t TypeOfView)
Usr_GetListsSelectedEncryptedUsrsCods (&Gbl.Usrs.Selected);
/***** Width for office hours *****/
- snprintf (Width,sizeof (Width),
- "%upx",
- Rec_RECORD_WIDTH);
+ snprintf (Width,sizeof (Width),"%upx",Rec_RECORD_WIDTH);
/***** Assign users listing type depending on current action *****/
Gbl.Usrs.Listing.RecsUsrs = Rec_RECORD_USERS_TEACHERS;
@@ -1396,7 +1386,7 @@ static void Rec_ListRecordsTchs (Rec_SharedRecordViewType_t TypeOfView)
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS)) // Get from the database the data of the student
@@ -1407,9 +1397,7 @@ static void Rec_ListRecordsTchs (Rec_SharedRecordViewType_t TypeOfView)
UsrDat.Accepted = Usr_CheckIfUsrHasAcceptedInCurrentCrs (&UsrDat);
/* Start container for this user */
- snprintf (RecordSectionId,sizeof (RecordSectionId),
- "record_%u",
- NumUsr);
+ snprintf (RecordSectionId,sizeof (RecordSectionId),"record_%u",NumUsr);
HTM_SECTION_Begin (RecordSectionId);
if (Gbl.Action.Act == ActPrnRecSevTch &&
@@ -1530,7 +1518,7 @@ static void Rec_WriteFormShowOfficeHoursSeveralTchs (bool ShowOfficeHours)
static void Rec_PutParamsShowOfficeHoursOneTch (void)
{
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
Par_PutHiddenParamChar ("ParamOfficeHours",'Y');
}
@@ -1707,7 +1695,7 @@ static void Rec_ShowCrsRecord (Rec_CourseRecordViewType_t TypeOfView,
Frm_StartFormAnchor (ActRcvRecOthUsr,Anchor);
Par_PutHiddenParamLong (NULL,"OriginalActCod",
Act_GetActCod (ActSeeRecSevStd)); // Original action, used to know where we came from
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
if (TypeOfView == Rec_CRS_LIST_SEVERAL_RECORDS)
Usr_PutHiddenParSelectedUsrsCods (&Gbl.Usrs.Selected);
}
@@ -1717,9 +1705,7 @@ static void Rec_ShowCrsRecord (Rec_CourseRecordViewType_t TypeOfView,
}
/***** Begin box and table *****/
- snprintf (StrRecordWidth,sizeof (StrRecordWidth),
- "%upx",
- Rec_RECORD_WIDTH);
+ snprintf (StrRecordWidth,sizeof (StrRecordWidth),"%upx",Rec_RECORD_WIDTH);
Box_BoxTableBegin (StrRecordWidth,NULL,
NULL,NULL,
Rec_RecordHelp[TypeOfView],Box_NOT_CLOSABLE,2);
@@ -1821,8 +1807,7 @@ static void Rec_ShowCrsRecord (Rec_CourseRecordViewType_t TypeOfView,
{
if (ThisFieldHasText)
{
- Str_Copy (Text,row[0],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Text,row[0],sizeof (Text));
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
Text,Cns_MAX_BYTES_TEXT,false);
HTM_Txt (Text);
@@ -1881,8 +1866,7 @@ void Rec_GetFieldsCrsRecordFromForm (void)
if (Rec_CheckIfICanEditField (Gbl.Crs.Records.LstFields.Lst[NumField].Visibility))
{
/* Get text from the form */
- snprintf (FieldParamName,sizeof (FieldParamName),
- "Field%ld",
+ snprintf (FieldParamName,sizeof (FieldParamName),"Field%ld",
Gbl.Crs.Records.LstFields.Lst[NumField].FieldCod);
Par_GetParToHTML (FieldParamName,Gbl.Crs.Records.LstFields.Lst[NumField].Text,Cns_MAX_BYTES_TEXT);
}
@@ -1994,7 +1978,7 @@ void Rec_AllocMemFieldsRecordsCrs (void)
NumField++)
if (Rec_CheckIfICanEditField (Gbl.Crs.Records.LstFields.Lst[NumField].Visibility))
/* Allocate memory for the texts of the fields */
- if ((Gbl.Crs.Records.LstFields.Lst[NumField].Text = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
+ if ((Gbl.Crs.Records.LstFields.Lst[NumField].Text = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
}
@@ -2300,7 +2284,7 @@ void Rec_ShowSharedUsrRecord (Rec_SharedRecordViewType_t TypeOfView,
break;
}
Frm_StartForm (NextAction);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod); // Existing user
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod); // Existing user
break;
case Rec_SHA_OTHER_NEW_USR_FORM:
switch (Gbl.Action.Act)
@@ -2635,7 +2619,7 @@ static void Rec_PutIconsCommands (__attribute__((unused)) void *Args)
void Rec_PutParamUsrCodEncrypted (__attribute__((unused)) void *Args)
{
- Usr_PutParamUsrCodEncrypted (Gbl.Record.UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (Gbl.Record.UsrDat->EnUsrCod);
}
static void Rec_PutParamsMyTsts (__attribute__((unused)) void *Args)
@@ -2661,7 +2645,7 @@ static void Rec_PutParamsWorks (__attribute__((unused)) void *Args)
static void Rec_PutParamsStudent (__attribute__((unused)) void *Args)
{
- Par_PutHiddenParamString (NULL,"UsrCodStd",Gbl.Record.UsrDat->EncryptedUsrCod);
+ Par_PutHiddenParamString (NULL,"UsrCodStd",Gbl.Record.UsrDat->EnUsrCod);
Grp_PutParamAllGroups ();
}
@@ -2747,7 +2731,7 @@ static void Rec_ShowFullName (struct UsrData *UsrDat)
HTM_DIV_Begin ("class=\"REC_NAME\"");
/***** First name *****/
- HTM_Txt (UsrDat->FirstName);
+ HTM_Txt (UsrDat->FrstName);
HTM_BR ();
/***** Surname 1 *****/
@@ -2780,7 +2764,7 @@ static void Rec_ShowNickname (struct UsrData *UsrDat,bool PutFormLinks)
/* Put form to go to public profile */
ItsMe = Usr_ItsMe (UsrDat->UsrCod);
Frm_StartForm (ActSeeOthPubPrf);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_BUTTON_SUBMIT_Begin (ItsMe ? Txt_My_public_profile :
Txt_Another_user_s_profile,
"BT_LINK REC_NICK",
@@ -3236,14 +3220,14 @@ static void Rec_ShowFirstName (struct UsrData *UsrDat,bool PutForm)
HTM_TD_Begin ("colspan=\"2\" class=\"REC_C2_BOT DAT_N LM\"");
if (PutForm)
HTM_INPUT_TEXT ("FirstName",Usr_MAX_CHARS_FIRSTNAME_OR_SURNAME,
- UsrDat->FirstName,
+ UsrDat->FrstName,
HTM_DONT_SUBMIT_ON_CHANGE,
"id=\"FirstName\" class=\"REC_C2_BOT_INPUT\""
" required=\"required\"");
- else if (UsrDat->FirstName[0])
+ else if (UsrDat->FrstName[0])
{
HTM_STRONG_Begin ();
- HTM_Txt (UsrDat->FirstName);
+ HTM_Txt (UsrDat->FrstName);
HTM_STRONG_End ();
}
HTM_TD_End ();
@@ -3700,8 +3684,7 @@ void Rec_GetUsrNameFromRecordForm (struct UsrData *UsrDat)
Str_ConvertToTitleType (Surname1);
// Surname 1 is mandatory, so avoid overwriting surname 1 with empty string
if (Surname1[0]) // New surname 1 not empty
- Str_Copy (UsrDat->Surname1,Surname1,
- Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
+ Str_Copy (UsrDat->Surname1,Surname1,sizeof (UsrDat->Surname1) - 1);
/***** Get surname 2 *****/
Par_GetParToText ("Surname2",UsrDat->Surname2,
@@ -3714,8 +3697,7 @@ void Rec_GetUsrNameFromRecordForm (struct UsrData *UsrDat)
Str_ConvertToTitleType (FirstName);
// First name is mandatory, so avoid overwriting first name with empty string
if (FirstName[0]) // New first name not empty
- Str_Copy (UsrDat->FirstName,FirstName,
- Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
+ Str_Copy (UsrDat->FrstName,FirstName,sizeof (UsrDat->FrstName) - 1);
/***** Build full name *****/
Usr_BuildFullName (UsrDat);
@@ -3782,7 +3764,7 @@ void Rec_ShowMySharedRecordAndMore (void)
(1 << Rol_TCH))); // ...or a teacher in any course
/***** If user has no name and surname, sex... *****/
- if (!Gbl.Usrs.Me.UsrDat.FirstName[0] ||
+ if (!Gbl.Usrs.Me.UsrDat.FrstName[0] ||
!Gbl.Usrs.Me.UsrDat.Surname1[0]) // 1. No name
Ale_ShowAlert (Ale_WARNING,Txt_Please_fill_in_your_record_card_including_your_name);
else if (Gbl.Usrs.Me.UsrDat.Sex == Usr_SEX_UNKNOWN) // 2. No sex
diff --git a/swad_report.c b/swad_report.c
index 66537733..726cc45b 100644
--- a/swad_report.c
+++ b/swad_report.c
@@ -343,14 +343,12 @@ static void Rep_GetCurrentDateTimeUTC (struct Rep_Report *Report)
{
/* Date and time as strings */
snprintf (Report->CurrentTimeUTC.StrDate,
- sizeof (Report->CurrentTimeUTC.StrDate),
- "%04d-%02d-%02d",
+ sizeof (Report->CurrentTimeUTC.StrDate),"%04d-%02d-%02d",
1900 + Report->tm_CurrentTime.tm_year, // year
1 + Report->tm_CurrentTime.tm_mon, // month
Report->tm_CurrentTime.tm_mday); // day of the month
snprintf (Report->CurrentTimeUTC.StrTime,
- sizeof (Report->CurrentTimeUTC.StrTime),
- "%02d:%02d:%02d",
+ sizeof (Report->CurrentTimeUTC.StrTime),"%02d:%02d:%02d",
Report->tm_CurrentTime.tm_hour, // hours
Report->tm_CurrentTime.tm_min, // minutes
Report->tm_CurrentTime.tm_sec); // seconds
@@ -383,16 +381,14 @@ static void Rep_CreateNewReportFile (struct Rep_Report *Report)
/***** Unique directory for the file with the report *****/
/* 1. Create a directory using the leftmost 2 chars of a unique name */
- snprintf (PathUniqueDirL,sizeof (PathUniqueDirL),
- "%s/%c%c",
+ snprintf (PathUniqueDirL,sizeof (PathUniqueDirL),"%s/%c%c",
Cfg_PATH_REP_PUBLIC,
Gbl.UniqueNameEncrypted[0],
Gbl.UniqueNameEncrypted[1]);
Fil_CreateDirIfNotExists (PathUniqueDirL);
/* 2. Create a directory using the rightmost 41 chars of a unique name */
- snprintf (PathUniqueDirR,sizeof (PathUniqueDirR),
- "%s/%s",
+ snprintf (PathUniqueDirR,sizeof (PathUniqueDirR),"%s/%s",
PathUniqueDirL,
&Gbl.UniqueNameEncrypted[2]);
if (mkdir (PathUniqueDirR,(mode_t) 0xFFF))
@@ -402,22 +398,19 @@ static void Rep_CreateNewReportFile (struct Rep_Report *Report)
snprintf (Report->FilenameReport,sizeof (Report->FilenameReport),
"%s_%06u_%06u.html",
Rep_FILENAME_ROOT,Report->CurrentTimeUTC.Date,Report->CurrentTimeUTC.Time);
- snprintf (PathFileReport,sizeof (PathFileReport),
- "%s/%s",
+ snprintf (PathFileReport,sizeof (PathFileReport),"%s/%s",
PathUniqueDirR,Report->FilenameReport);
if ((Gbl.F.Rep = fopen (PathFileReport,"wb")) == NULL)
Lay_ShowErrorAndExit ("Can not create report file.");
/***** Permalink *****/
- snprintf (Permalink,sizeof (Permalink),
- "%s/%c%c/%s/%s",
+ snprintf (Permalink,sizeof (Permalink),"%s/%c%c/%s/%s",
Cfg_URL_REP_PUBLIC,
Gbl.UniqueNameEncrypted[0],
Gbl.UniqueNameEncrypted[1],
&Gbl.UniqueNameEncrypted[2],
Report->FilenameReport);
- Str_Copy (Report->Permalink,Permalink,
- Cns_MAX_BYTES_WWW);
+ Str_Copy (Report->Permalink,Permalink,sizeof (Report->Permalink) - 1);
}
/*****************************************************************************/
@@ -1439,8 +1432,7 @@ static void Rep_RemoveUsrReportsFiles (long UsrCod)
row = mysql_fetch_row (mysql_res);
/* Remove report directory and file */
- snprintf (PathUniqueDirReport,sizeof (PathUniqueDirReport),
- "%s/%s/%s",
+ snprintf (PathUniqueDirReport,sizeof (PathUniqueDirReport),"%s/%s/%s",
Cfg_PATH_REP_PUBLIC,row[0],row[1]);
Fil_RemoveTree (PathUniqueDirReport);
}
diff --git a/swad_room.c b/swad_room.c
index 76f57b9c..fd25402e 100644
--- a/swad_room.c
+++ b/swad_room.c
@@ -585,9 +585,7 @@ void Roo_GetListRooms (struct Roo_Rooms *Rooms,
Rooms->Num = (unsigned) NumRows;
/***** Create list with courses in centre *****/
- if ((Rooms->Lst = (struct Roo_Room *)
- calloc (NumRows,
- sizeof (struct Roo_Room))) == NULL)
+ if ((Rooms->Lst = calloc (NumRows,sizeof (*Rooms->Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the rooms *****/
@@ -619,13 +617,9 @@ void Roo_GetListRooms (struct Roo_Rooms *Rooms,
/* Get type (row[4]) */
Room->Type = Roo_GetTypeFromString (row[4]);
- /* Get the short name of the room (row[5]) */
- Str_Copy (Room->ShrtName,row[5],
- Roo_MAX_BYTES_SHRT_NAME);
-
- /* Get the full name of the room (row[6]) */
- Str_Copy (Room->FullName,row[6],
- Roo_MAX_BYTES_FULL_NAME);
+ /* Get the short (row[5]) and full (row[6]) names of the room */
+ Str_Copy (Room->ShrtName,row[5],sizeof (Room->ShrtName) - 1);
+ Str_Copy (Room->FullName,row[6],sizeof (Room->FullName) - 1);
/* Get seating capacity in this room (row[7]) */
if (sscanf (row[7],"%u",&Room->Capacity) != 1)
@@ -634,8 +628,7 @@ void Roo_GetListRooms (struct Roo_Rooms *Rooms,
case Roo_ONLY_SHRT_NAME:
default:
/* Get the short name of the room (row[1]) */
- Str_Copy (Room->ShrtName,row[1],
- Roo_MAX_BYTES_SHRT_NAME);
+ Str_Copy (Room->ShrtName,row[1],sizeof (Room->ShrtName) - 1);
break;
}
}
@@ -693,13 +686,9 @@ static void Roo_GetDataOfRoomByCod (struct Roo_Room *Room)
/* Get type (row[3]) */
Room->Type = Roo_GetTypeFromString (row[3]);
- /* Get the short name of the room (row[4]) */
- Str_Copy (Room->ShrtName,row[4],
- Roo_MAX_BYTES_SHRT_NAME);
-
- /* Get the full name of the room (row[5]) */
- Str_Copy (Room->FullName,row[5],
- Roo_MAX_BYTES_FULL_NAME);
+ /* Get the short (row[4]) and full (row[5]) names of the room */
+ Str_Copy (Room->ShrtName,row[4],sizeof (Room->ShrtName) - 1);
+ Str_Copy (Room->FullName,row[5],sizeof (Room->FullName) - 1);
/* Get seating capacity in this room (row[6]) */
if (sscanf (row[6],"%u",&Room->Capacity) != 1)
@@ -721,16 +710,16 @@ static void Roo_GetBldShrtName (struct Roo_Room *Room,const char *BldShrtNameFro
if (Room->BldCod < 0)
Str_Copy (Room->BldShrtName,Txt_No_assigned_building,
- Bld_MAX_BYTES_SHRT_NAME);
+ sizeof (Room->BldShrtName) - 1);
else if (Room->BldCod == 0)
Str_Copy (Room->BldShrtName,Txt_Another_building,
- Bld_MAX_BYTES_SHRT_NAME);
+ sizeof (Room->BldShrtName) - 1);
else // Room->BldCod > 0
{
Room->BldShrtName[0] = '\0';
if (BldShrtNameFromDB)
Str_Copy (Room->BldShrtName,BldShrtNameFromDB,
- Bld_MAX_BYTES_SHRT_NAME);
+ sizeof (Room->BldShrtName) - 1);
}
}
@@ -1288,8 +1277,7 @@ static void Roo_RenameRoom (Cns_ShrtOrFullName_t ShrtOrFullName)
Ale_CreateAlertYouCanNotLeaveFieldEmpty ();
/***** Update room name *****/
- Str_Copy (CurrentClaName,NewClaName,
- MaxBytes);
+ Str_Copy (CurrentClaName,NewClaName,MaxBytes);
}
/*****************************************************************************/
@@ -1383,9 +1371,7 @@ void Roo_ChangeCapacity (void)
static void Roo_WriteCapacity (char Str[Cns_MAX_DECIMAL_DIGITS_UINT + 1],unsigned Capacity)
{
if (Capacity <= Roo_MAX_CAPACITY)
- snprintf (Str,Cns_MAX_DECIMAL_DIGITS_UINT + 1,
- "%u",
- Capacity);
+ snprintf (Str,Cns_MAX_DECIMAL_DIGITS_UINT + 1,"%u",Capacity);
else
Str[0] = '\0';
}
@@ -1638,8 +1624,8 @@ static void Roo_EditingRoomConstructor (void)
Lay_ShowErrorAndExit ("Error initializing room.");
/***** Allocate memory for room *****/
- if ((Roo_EditingRoom = (struct Roo_Room *) malloc (sizeof (struct Roo_Room))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for room.");
+ if ((Roo_EditingRoom = malloc (sizeof (*Roo_EditingRoom))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/***** Reset room *****/
Roo_EditingRoom->RooCod = -1L;
diff --git a/swad_search.c b/swad_search.c
index 15af5be6..9564d1db 100644
--- a/swad_search.c
+++ b/swad_search.c
@@ -459,8 +459,7 @@ static unsigned Sch_SearchCountriesInDB (const char *RangeQuery)
if (Sch_CheckIfIHavePermissionToSearch (Sch_SEARCH_COUNTRIES))
{
/***** Split countries string into words *****/
- snprintf (FieldName,sizeof (FieldName),
- "Name_%s",
+ snprintf (FieldName,sizeof (FieldName),"Name_%s",
Lan_STR_LANG_ID[Gbl.Prefs.Language]);
if (Sch_BuildSearchQuery (SearchQuery,FieldName,NULL,NULL))
{
@@ -1111,26 +1110,18 @@ bool Sch_BuildSearchQuery (char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1],
Sch_MAX_BYTES_SEARCH_QUERY) // Prevent string overflow
break;
if (NumWords)
- Str_Concat (SearchQuery," AND ",
- Sch_MAX_BYTES_SEARCH_QUERY);
- Str_Concat (SearchQuery,FieldName,
- Sch_MAX_BYTES_SEARCH_QUERY);
- Str_Concat (SearchQuery," LIKE ",
- Sch_MAX_BYTES_SEARCH_QUERY);
+ Str_Concat (SearchQuery," AND ",Sch_MAX_BYTES_SEARCH_QUERY);
+ Str_Concat (SearchQuery,FieldName,Sch_MAX_BYTES_SEARCH_QUERY);
+ Str_Concat (SearchQuery," LIKE ",Sch_MAX_BYTES_SEARCH_QUERY);
if (CharSet)
if (CharSet[0])
- Str_Concat (SearchQuery,CharSet,
- Sch_MAX_BYTES_SEARCH_QUERY);
- Str_Concat (SearchQuery,"'%",
- Sch_MAX_BYTES_SEARCH_QUERY);
- Str_Concat (SearchQuery,SearchWords[NumWords],
- Sch_MAX_BYTES_SEARCH_QUERY);
- Str_Concat (SearchQuery,"%'",
- Sch_MAX_BYTES_SEARCH_QUERY);
+ Str_Concat (SearchQuery,CharSet,Sch_MAX_BYTES_SEARCH_QUERY);
+ Str_Concat (SearchQuery,"'%",Sch_MAX_BYTES_SEARCH_QUERY);
+ Str_Concat (SearchQuery,SearchWords[NumWords],Sch_MAX_BYTES_SEARCH_QUERY);
+ Str_Concat (SearchQuery,"%'",Sch_MAX_BYTES_SEARCH_QUERY);
if (Collate)
if (Collate[0])
- Str_Concat (SearchQuery,Collate,
- Sch_MAX_BYTES_SEARCH_QUERY);
+ Str_Concat (SearchQuery,Collate,Sch_MAX_BYTES_SEARCH_QUERY);
}
}
diff --git a/swad_session.c b/swad_session.c
index 20013210..c911b762 100644
--- a/swad_session.c
+++ b/swad_session.c
@@ -28,7 +28,6 @@
#include // To access MySQL databases
#include // For NULL
#include // For sprintf
-#include // For malloc and free
#include // For string functions
#include "swad_connected.h"
@@ -80,8 +79,7 @@ void Ses_GetNumSessions (void)
void Ses_CreateSession (void)
{
/***** Create a unique name for the session *****/
- Str_Copy (Gbl.Session.Id,Gbl.UniqueNameEncrypted,
- Cns_BYTES_SESSION_ID);
+ Str_Copy (Gbl.Session.Id,Gbl.UniqueNameEncrypted,sizeof (Gbl.Session.Id) - 1);
/***** Check that session is not open *****/
if (Ses_CheckIfSessionExists (Gbl.Session.Id))
@@ -288,7 +286,7 @@ bool Ses_GetSessionData (void)
/***** Get password (row[1]) *****/
Str_Copy (Gbl.Usrs.Me.LoginEncryptedPassword,row[1],
- Pwd_BYTES_ENCRYPTED_PASSWORD);
+ sizeof (Gbl.Usrs.Me.LoginEncryptedPassword) - 1);
/***** Get logged user type (row[2]) *****/
if (sscanf (row[2],"%u",&Gbl.Usrs.Me.Role.FromSession) != 1)
@@ -321,8 +319,7 @@ bool Ses_GetSessionData (void)
Gbl.Search.WhatToSearch = Sch_WHAT_TO_SEARCH_DEFAULT;
/* Get search string (row[9]) */
- Str_Copy (Gbl.Search.Str,row[9],
- Sch_MAX_BYTES_STRING_TO_FIND);
+ Str_Copy (Gbl.Search.Str,row[9],sizeof (Gbl.Search.Str) - 1);
}
Result = true;
@@ -440,8 +437,7 @@ void Ses_GetHiddenParFromDB (const char *ParamName,char *ParamValue,
ParameterIsTooBig = (strlen (row[0]) > MaxBytes);
if (!ParameterIsTooBig)
- Str_Copy (ParamValue,row[0],
- MaxBytes);
+ Str_Copy (ParamValue,row[0],MaxBytes);
}
/***** Free structure that stores the query result *****/
diff --git a/swad_setting.c b/swad_setting.c
index 235bf7b3..fd4530b7 100644
--- a/swad_setting.c
+++ b/swad_setting.c
@@ -262,8 +262,7 @@ static void Set_PutIconsToSelectSideCols (void)
"PREF_OFF");
Frm_StartForm (ActChgCol);
Par_PutHiddenParamUnsigned (NULL,"SideCols",SideCols);
- snprintf (Icon,sizeof (Icon),
- "layout%u%u_32x20.gif",
+ snprintf (Icon,sizeof (Icon),"layout%u%u_32x20.gif",
SideCols >> 1,SideCols & 1);
Ico_PutSettingIconLink (Icon,Txt_LAYOUT_SIDE_COLUMNS[SideCols]);
Frm_EndForm ();
diff --git a/swad_statistic.c b/swad_statistic.c
index b2c988fb..6af920f1 100644
--- a/swad_statistic.c
+++ b/swad_statistic.c
@@ -201,8 +201,7 @@ The IP address of the remote host making the request.
void Sta_GetRemoteAddr (void)
{
if (getenv ("REMOTE_ADDR"))
- Str_Copy (Gbl.IP,getenv ("REMOTE_ADDR"),
- Cns_MAX_BYTES_IP);
+ Str_Copy (Gbl.IP,getenv ("REMOTE_ADDR"),sizeof (Gbl.IP) - 1);
else
Gbl.IP[0] = '\0';
}
@@ -920,8 +919,7 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
switch (Stats.CountType)
{
case Sta_TOTAL_CLICKS:
- Str_Copy (StrQueryCountType,"COUNT(*)",
- Sta_MAX_BYTES_COUNT_TYPE);
+ Str_Copy (StrQueryCountType,"COUNT(*)",sizeof (StrQueryCountType) - 1);
break;
case Sta_DISTINCT_USRS:
sprintf (StrQueryCountType,"COUNT(DISTINCT(%s.UsrCod))",LogTable);
@@ -939,7 +937,7 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
/***** Select clicks from the table of log *****/
/* Allocate memory for the query */
- if ((Query = (char *) malloc (Sta_MAX_BYTES_QUERY_ACCESS + 1)) == NULL)
+ if ((Query = malloc (Sta_MAX_BYTES_QUERY_ACCESS + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
/* Start the query */
@@ -1079,8 +1077,7 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
LogTable,
(long) Gbl.DateRange.TimeUTC[Dat_START_TIME],
(long) Gbl.DateRange.TimeUTC[Dat_END_TIME ]);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
switch (GlobalOrCourse)
{
@@ -1096,8 +1093,7 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
{
sprintf (QueryAux," AND %s.CtyCod=%ld",
LogTable,Gbl.Hierarchy.Cty.CtyCod);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
}
break;
case Hie_Lvl_INS:
@@ -1105,8 +1101,7 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
{
sprintf (QueryAux," AND %s.InsCod=%ld",
LogTable,Gbl.Hierarchy.Ins.InsCod);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
}
break;
case Hie_Lvl_CTR:
@@ -1114,8 +1109,7 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
{
sprintf (QueryAux," AND %s.CtrCod=%ld",
LogTable,Gbl.Hierarchy.Ctr.CtrCod);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
}
break;
case Hie_Lvl_DEG:
@@ -1123,8 +1117,7 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
{
sprintf (QueryAux," AND %s.DegCod=%ld",
LogTable,Gbl.Hierarchy.Deg.DegCod);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
}
break;
case Hie_Lvl_CRS:
@@ -1132,8 +1125,7 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
{
sprintf (QueryAux," AND %s.CrsCod=%ld",
LogTable,Gbl.Hierarchy.Crs.CrsCod);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
}
break;
}
@@ -1201,8 +1193,7 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
LogTable,Gbl.Usrs.Me.UsrDat.UsrCod);
break;
}
- Str_Concat (Query,StrRole,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,StrRole,Sta_MAX_BYTES_QUERY_ACCESS);
switch (Stats.ClicksGroupedBy)
{
@@ -1210,14 +1201,12 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
case Sta_CLICKS_GBL_PER_API_FUNCTION:
sprintf (QueryAux," AND %s.LogCod=log_ws.LogCod",
LogTable);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
break;
case Sta_CLICKS_GBL_PER_BANNER:
sprintf (QueryAux," AND %s.LogCod=log_banners.LogCod",
LogTable);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
break;
default:
break;
@@ -1226,8 +1215,7 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
case Sta_SHOW_COURSE_ACCESSES:
sprintf (QueryAux," AND %s.CrsCod=%ld",
LogTable,Gbl.Hierarchy.Crs.CrsCod);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
/***** Initialize data structure of the user *****/
Usr_UsrDataConstructor (&UsrDat);
@@ -1237,7 +1225,7 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
if (UsrDat.UsrCod > 0)
@@ -1249,13 +1237,11 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
NumUsr ? " OR %s.UsrCod=%ld" :
" AND (%s.UsrCod=%ld",
LogTable,UsrDat.UsrCod);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
NumUsr++;
}
}
- Str_Concat (Query,")",
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,")",Sta_MAX_BYTES_QUERY_ACCESS);
/***** Free memory used by the data of the user *****/
Usr_UsrDataDestructor (&UsrDat);
@@ -1267,62 +1253,51 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
{
sprintf (QueryAux," AND %s.ActCod=%ld",
LogTable,Act_GetActCod (Stats.NumAction));
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
}
/* End the query */
switch (Stats.ClicksGroupedBy)
{
case Sta_CLICKS_CRS_DETAILED_LIST:
- Str_Concat (Query," ORDER BY F",
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query," ORDER BY F",Sta_MAX_BYTES_QUERY_ACCESS);
break;
case Sta_CLICKS_CRS_PER_USR:
sprintf (QueryAux," GROUP BY %s.UsrCod ORDER BY Num DESC",LogTable);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
break;
case Sta_CLICKS_CRS_PER_DAY:
case Sta_CLICKS_GBL_PER_DAY:
- Str_Concat (Query," GROUP BY Day DESC",
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query," GROUP BY Day DESC",Sta_MAX_BYTES_QUERY_ACCESS);
break;
case Sta_CLICKS_CRS_PER_DAY_AND_HOUR:
case Sta_CLICKS_GBL_PER_DAY_AND_HOUR:
- Str_Concat (Query," GROUP BY Day DESC,Hour",
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query," GROUP BY Day DESC,Hour",Sta_MAX_BYTES_QUERY_ACCESS);
break;
case Sta_CLICKS_CRS_PER_WEEK:
case Sta_CLICKS_GBL_PER_WEEK:
- Str_Concat (Query," GROUP BY Week DESC",
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query," GROUP BY Week DESC",Sta_MAX_BYTES_QUERY_ACCESS);
break;
case Sta_CLICKS_CRS_PER_MONTH:
case Sta_CLICKS_GBL_PER_MONTH:
- Str_Concat (Query," GROUP BY Month DESC",
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query," GROUP BY Month DESC",Sta_MAX_BYTES_QUERY_ACCESS);
break;
case Sta_CLICKS_CRS_PER_YEAR:
case Sta_CLICKS_GBL_PER_YEAR:
- Str_Concat (Query," GROUP BY Year DESC",
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query," GROUP BY Year DESC",Sta_MAX_BYTES_QUERY_ACCESS);
break;
case Sta_CLICKS_CRS_PER_HOUR:
case Sta_CLICKS_GBL_PER_HOUR:
- Str_Concat (Query," GROUP BY Hour",
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query," GROUP BY Hour",Sta_MAX_BYTES_QUERY_ACCESS);
break;
case Sta_CLICKS_CRS_PER_MINUTE:
case Sta_CLICKS_GBL_PER_MINUTE:
- Str_Concat (Query," GROUP BY Minute",
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query," GROUP BY Minute",Sta_MAX_BYTES_QUERY_ACCESS);
break;
case Sta_CLICKS_CRS_PER_ACTION:
case Sta_CLICKS_GBL_PER_ACTION:
sprintf (QueryAux," GROUP BY %s.ActCod ORDER BY Num DESC",LogTable);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
break;
case Sta_CLICKS_GBL_PER_PLUGIN:
Str_Concat (Query," GROUP BY log_ws.PlgCod ORDER BY Num DESC",
@@ -1338,28 +1313,23 @@ static void Sta_ShowHits (Sta_GlobalOrCourseAccesses_t GlobalOrCourse)
break;
case Sta_CLICKS_GBL_PER_COUNTRY:
sprintf (QueryAux," GROUP BY %s.CtyCod ORDER BY Num DESC",LogTable);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
break;
case Sta_CLICKS_GBL_PER_INSTITUTION:
sprintf (QueryAux," GROUP BY %s.InsCod ORDER BY Num DESC",LogTable);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
break;
case Sta_CLICKS_GBL_PER_CENTRE:
sprintf (QueryAux," GROUP BY %s.CtrCod ORDER BY Num DESC",LogTable);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
break;
case Sta_CLICKS_GBL_PER_DEGREE:
sprintf (QueryAux," GROUP BY %s.DegCod ORDER BY Num DESC",LogTable);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
break;
case Sta_CLICKS_GBL_PER_COURSE:
sprintf (QueryAux," GROUP BY %s.CrsCod ORDER BY Num DESC",LogTable);
- Str_Concat (Query,QueryAux,
- Sta_MAX_BYTES_QUERY_ACCESS);
+ Str_Concat (Query,QueryAux,Sta_MAX_BYTES_QUERY_ACCESS);
break;
}
/***** Write query for debug *****/
@@ -3913,20 +3883,14 @@ void Sta_WriteTimeToGenerateAndSendPage (void)
void Sta_WriteTime (char Str[Dat_MAX_BYTES_TIME],long TimeInMicroseconds)
{
if (TimeInMicroseconds < 1000L)
- snprintf (Str,Dat_MAX_BYTES_TIME + 1,
- "%ld µs",
- TimeInMicroseconds);
+ snprintf (Str,Dat_MAX_BYTES_TIME + 1,"%ld µs",TimeInMicroseconds);
else if (TimeInMicroseconds < 1000000L)
- snprintf (Str,Dat_MAX_BYTES_TIME + 1,
- "%ld ms",
- TimeInMicroseconds / 1000);
+ snprintf (Str,Dat_MAX_BYTES_TIME + 1,"%ld ms",TimeInMicroseconds / 1000);
else if (TimeInMicroseconds < (60 * 1000000L))
- snprintf (Str,Dat_MAX_BYTES_TIME + 1,
- "%.1f s",
- (double) TimeInMicroseconds / 1E6);
+ snprintf (Str,Dat_MAX_BYTES_TIME + 1,"%.1f s",
+ (double) TimeInMicroseconds / 1E6);
else
- snprintf (Str,Dat_MAX_BYTES_TIME + 1,
- "%ld min, %ld s",
+ snprintf (Str,Dat_MAX_BYTES_TIME + 1,"%ld min, %ld s",
TimeInMicroseconds / (60 * 1000000L),
(TimeInMicroseconds / 1000000L) % 60);
}
diff --git a/swad_string.c b/swad_string.c
index 597fb6ec..c16fd58e 100644
--- a/swad_string.c
+++ b/swad_string.c
@@ -305,12 +305,10 @@ void Str_InsertLinks (char *Txt,unsigned long MaxLength,size_t MaxCharsURLOnScre
Gbl.Form.Num++;
if (Gbl.Usrs.Me.Logged)
snprintf (Gbl.Form.UniqueId,sizeof (Gbl.Form.UniqueId),
- "form_%s_%d",
- Gbl.UniqueNameEncrypted,Gbl.Form.Num);
+ "form_%s_%d",Gbl.UniqueNameEncrypted,Gbl.Form.Num);
else
snprintf (Gbl.Form.Id,sizeof (Gbl.Form.Id),
- "form_%d",
- Gbl.Form.Num);
+ "form_%d",Gbl.Form.Num);
/* Store first part of anchor */
Frm_SetParamsForm (ParamsStr,ActSeeOthPubPrf,true);
@@ -324,7 +322,7 @@ void Str_InsertLinks (char *Txt,unsigned long MaxLength,size_t MaxCharsURLOnScre
Gbl.Form.Id,
ParamsStr);
Anchor1NickLength = strlen (Anchor1Nick);
- if ((Links[NumLinks].Anchor1Nick = (char *) malloc (Anchor1NickLength + 1)) == NULL)
+ if ((Links[NumLinks].Anchor1Nick = malloc (Anchor1NickLength + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
strcpy (Links[NumLinks].Anchor1Nick,Anchor1Nick);
Links[NumLinks].Anchor1NickLength = Anchor1NickLength;
@@ -337,7 +335,7 @@ void Str_InsertLinks (char *Txt,unsigned long MaxLength,size_t MaxCharsURLOnScre
Gbl.Usrs.Me.Logged ? Gbl.Form.UniqueId :
Gbl.Form.Id);
Anchor2NickLength = strlen (Anchor2Nick);
- if ((Links[NumLinks].Anchor2Nick = (char *) malloc (Anchor2NickLength + 1)) == NULL)
+ if ((Links[NumLinks].Anchor2Nick = malloc (Anchor2NickLength + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
strcpy (Links[NumLinks].Anchor2Nick,Anchor2Nick);
Links[NumLinks].Anchor2NickLength = Anchor2NickLength;
@@ -1148,7 +1146,7 @@ void Str_ChangeFormat (Str_ChangeFrom_t ChangeFrom,Str_ChangeTo_t ChangeTo,
if (ChangeTo != Str_DONT_CHANGE)
{
/***** Allocate memory for a destination string where to do the changes *****/
- if ((StrDst = (char *) malloc (MaxLengthStr + 1)) == NULL)
+ if ((StrDst = malloc (MaxLengthStr + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Make the change *****/
@@ -1287,12 +1285,12 @@ void Str_ChangeFormat (Str_ChangeFrom_t ChangeFrom,Str_ChangeTo_t ChangeTo,
Str_Concat (StrSpecialChar,
ThereIsSpaceChar ? " " :
" ", // The first space
- Str_MAX_BYTES_SPECIAL_CHAR);
+ sizeof (StrSpecialChar) - 1);
for (i = 1;
i < NumSpacesTab;
i++) // Rest of spaces, except the first
Str_Concat (StrSpecialChar," ", // Add a space
- Str_MAX_BYTES_SPECIAL_CHAR);
+ sizeof (StrSpecialChar) - 1);
NumPrintableCharsFromReturn += NumSpacesTab;
}
else
@@ -1305,7 +1303,7 @@ void Str_ChangeFormat (Str_ChangeFrom_t ChangeFrom,Str_ChangeTo_t ChangeTo,
case 0x0A: /* \n */
if (ChangeTo == Str_TO_RIGOROUS_HTML)
Str_Copy (StrSpecialChar,"
",
- Str_MAX_BYTES_SPECIAL_CHAR);
+ sizeof (StrSpecialChar) - 1);
else
{
StrSpecialChar[0] = Str_LF[0];
@@ -1328,7 +1326,7 @@ void Str_ChangeFormat (Str_ChangeFrom_t ChangeFrom,Str_ChangeTo_t ChangeTo,
case 0x20: /* Space */
if (ChangeTo == Str_TO_RIGOROUS_HTML && ThereIsSpaceChar)
Str_Copy (StrSpecialChar," ",
- Str_MAX_BYTES_SPECIAL_CHAR);
+ sizeof (StrSpecialChar) - 1);
else
{
StrSpecialChar[0] = ' ';
@@ -1346,7 +1344,7 @@ void Str_ChangeFormat (Str_ChangeFrom_t ChangeFrom,Str_ChangeTo_t ChangeTo,
}
else
Str_Copy (StrSpecialChar,""", // Double comilla is stored as HTML code to avoid problems when displaying it
- Str_MAX_BYTES_SPECIAL_CHAR);
+ sizeof (StrSpecialChar) - 1);
NumPrintableCharsFromReturn++;
ThereIsSpaceChar = false;
break;
@@ -1371,7 +1369,7 @@ void Str_ChangeFormat (Str_ChangeFrom_t ChangeFrom,Str_ChangeTo_t ChangeTo,
}
else
Str_Copy (StrSpecialChar,"'", // Single comilla is stored as HTML entity to avoid problem when querying database (SQL code injection)
- Str_MAX_BYTES_SPECIAL_CHAR);
+ sizeof (StrSpecialChar) - 1);
NumPrintableCharsFromReturn++;
ThereIsSpaceChar = false;
break;
@@ -1407,7 +1405,7 @@ void Str_ChangeFormat (Str_ChangeFrom_t ChangeFrom,Str_ChangeTo_t ChangeTo,
}
else
Str_Copy (StrSpecialChar,"<", // "<" is stored as HTML code to avoid problems when displaying it
- Str_MAX_BYTES_SPECIAL_CHAR);
+ sizeof (StrSpecialChar) - 1);
NumPrintableCharsFromReturn++;
ThereIsSpaceChar = false;
break;
@@ -1419,7 +1417,7 @@ void Str_ChangeFormat (Str_ChangeFrom_t ChangeFrom,Str_ChangeTo_t ChangeTo,
}
else
Str_Copy (StrSpecialChar,">", // ">" is stored as HTML code to avoid problems when displaying it
- Str_MAX_BYTES_SPECIAL_CHAR);
+ sizeof (StrSpecialChar) - 1);
NumPrintableCharsFromReturn++;
ThereIsSpaceChar = false;
break;
@@ -1444,7 +1442,7 @@ void Str_ChangeFormat (Str_ChangeFrom_t ChangeFrom,Str_ChangeTo_t ChangeTo,
}
else
Str_Copy (StrSpecialChar,"\", // "\" is stored as HTML code to avoid problems when displaying it
- Str_MAX_BYTES_SPECIAL_CHAR);
+ sizeof (StrSpecialChar) - 1);
NumPrintableCharsFromReturn++;
ThereIsSpaceChar = false;
break;
@@ -2579,16 +2577,14 @@ void Str_SplitFullPathIntoPathAndFileName (const char FullPath[PATH_MAX + 1],
LengthUntilFileName = (size_t) (PtrFileName - FullPath); // Last slash included
if (LengthUntilFileName > 1)
{
- Str_Copy (PathWithoutFileName,FullPath,
- PATH_MAX);
+ Str_Copy (PathWithoutFileName,FullPath,PATH_MAX);
PathWithoutFileName[LengthUntilFileName - 1] = '\0'; // Do not copy ending slash
}
else
PathWithoutFileName[0] = '\0';
/***** Get FileName *****/
- Str_Copy (FileName,PtrFileName,
- NAME_MAX);
+ Str_Copy (FileName,PtrFileName,NAME_MAX);
}
/*****************************************************************************/
@@ -3043,8 +3039,7 @@ void Str_Concat (char *Dst,const char *Src,size_t DstSize)
DstLength = strlen (Dst);
if (DstLength > DstSize)
{
- snprintf (ErrorTxt,sizeof (ErrorTxt),
- "%lu-chars buffer has %lu chars!",
+ snprintf (ErrorTxt,sizeof (ErrorTxt),"%lu-chars buffer has %lu chars!",
DstSize,DstLength);
Lay_ShowErrorAndExit (ErrorTxt);
}
diff --git a/swad_survey.c b/swad_survey.c
index e02c077e..45a9953b 100644
--- a/swad_survey.c
+++ b/swad_survey.c
@@ -1055,7 +1055,8 @@ static void Svy_GetListSurveys (struct Svy_Surveys *Surveys)
Surveys->Num = (unsigned) NumRows;
/***** Create list of surveys *****/
- if ((Surveys->LstSvyCods = (long *) calloc (NumRows,sizeof (long))) == NULL)
+ if ((Surveys->LstSvyCods = calloc (NumRows,
+ sizeof (*Surveys->LstSvyCods))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get the surveys codes *****/
@@ -1301,8 +1302,7 @@ void Svy_GetDataOfSurveyByCod (struct Svy_Survey *Svy)
Svy->Status.Open = (row[8][0] == '1');
/* Get the title of the survey (row[9]) */
- Str_Copy (Svy->Title,row[9],
- Svy_MAX_BYTES_SURVEY_TITLE);
+ Str_Copy (Svy->Title,row[9],strlen (Svy->Title) - 1);
/* Get number of questions and number of users who have already answer this survey */
Svy->NumQsts = Svy_GetNumQstsSvy (Svy->SvyCod);
@@ -1493,8 +1493,7 @@ static void Svy_GetSurveyTxtFromDB (long SvyCod,char Txt[Cns_MAX_BYTES_TEXT + 1]
{
/* Get info text */
row = mysql_fetch_row (mysql_res);
- Str_Copy (Txt,row[0],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Txt,row[0],Cns_MAX_BYTES_TEXT);
}
else
Txt[0] = '\0';
@@ -1532,17 +1531,15 @@ void Svy_GetNotifSurvey (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
row = mysql_fetch_row (mysql_res);
/***** Get summary *****/
- Str_Copy (SummaryStr,row[0],
- Ntf_MAX_BYTES_SUMMARY);
+ Str_Copy (SummaryStr,row[0],Ntf_MAX_BYTES_SUMMARY);
/***** Get content *****/
if (GetContent)
{
Length = strlen (row[1]);
- if ((*ContentStr = (char *) malloc (Length + 1)) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for notification content.");
- Str_Copy (*ContentStr,row[1],
- Length);
+ if ((*ContentStr = malloc (Length + 1)) == NULL)
+ Lay_NotEnoughMemoryExit ();
+ Str_Copy (*ContentStr,row[1],Length);
}
}
@@ -2708,8 +2705,7 @@ static void Svy_ShowFormEditOneQst (struct Svy_Surveys *Surveys,
SvyQst->AnswerType = Svy_ConvertFromStrAnsTypDBToAnsTyp (row[1]);
/* Get the stem of the question from the database (row[2]) */
- Str_Copy (Txt,row[2],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Txt,row[2],Cns_MAX_BYTES_TEXT);
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
@@ -2728,8 +2724,7 @@ static void Svy_ShowFormEditOneQst (struct Svy_Surveys *Surveys,
/* Abort on error */
Ale_ShowAlertsAndExit ();
- Str_Copy (SvyQst->AnsChoice[NumAns].Text,row[2],
- Svy_MAX_BYTES_ANSWER);
+ Str_Copy (SvyQst->AnsChoice[NumAns].Text,row[2],Svy_MAX_BYTES_ANSWER);
}
/* Free structure that stores the query result */
DB_FreeMySQLResult (&mysql_res);
@@ -2968,7 +2963,7 @@ static bool Svy_AllocateTextChoiceAnswer (struct Svy_Question *SvyQst,
unsigned NumAns)
{
Svy_FreeTextChoiceAnswer (SvyQst,NumAns);
- if ((SvyQst->AnsChoice[NumAns].Text = (char *) malloc (Svy_MAX_BYTES_ANSWER + 1)) == NULL)
+ if ((SvyQst->AnsChoice[NumAns].Text = malloc (Svy_MAX_BYTES_ANSWER + 1)) == NULL)
{
Ale_CreateAlert (Ale_ERROR,NULL,
"Not enough memory to store answer.");
@@ -3057,9 +3052,7 @@ void Svy_ReceiveQst (void)
if (!Svy_AllocateTextChoiceAnswer (&SvyQst,NumAns))
/* Abort on error */
Ale_ShowAlertsAndExit ();
- snprintf (AnsStr,sizeof (AnsStr),
- "AnsStr%u",
- NumAns);
+ snprintf (AnsStr,sizeof (AnsStr),"AnsStr%u",NumAns);
Par_GetParToHTML (AnsStr,SvyQst.AnsChoice[NumAns].Text,Svy_MAX_BYTES_ANSWER);
}
@@ -3438,10 +3431,9 @@ static void Svy_WriteQstStem (const char *Stem)
/* Convert the stem, that is in HTML, to rigorous HTML */
Length = strlen (Stem) * Str_MAX_BYTES_PER_CHAR;
- if ((HeadingRigorousHTML = (char *) malloc (Length + 1)) == NULL)
+ if ((HeadingRigorousHTML = malloc (Length + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
- Str_Copy (HeadingRigorousHTML,Stem,
- Length);
+ Str_Copy (HeadingRigorousHTML,Stem,Length);
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
HeadingRigorousHTML,Length,false);
@@ -3495,8 +3487,7 @@ static void Svy_WriteAnswersOfAQst (struct Svy_Survey *Svy,
/* Abort on error */
Ale_ShowAlertsAndExit ();
- Str_Copy (SvyQst->AnsChoice[NumAns].Text,row[2],
- Svy_MAX_BYTES_ANSWER);
+ Str_Copy (SvyQst->AnsChoice[NumAns].Text,row[2],Svy_MAX_BYTES_ANSWER);
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
SvyQst->AnsChoice[NumAns].Text,Svy_MAX_BYTES_ANSWER,false);
@@ -3507,9 +3498,8 @@ static void Svy_WriteAnswersOfAQst (struct Svy_Survey *Svy,
{
/* Write selector to choice this answer */
HTM_TD_Begin ("class=\"LT\"");
- snprintf (StrAns,sizeof (StrAns),
- "Ans%010u",
- (unsigned) SvyQst->QstCod);
+ snprintf (StrAns,sizeof (StrAns),"Ans%010u",
+ (unsigned) SvyQst->QstCod);
if (SvyQst->AnswerType == Svy_ANS_UNIQUE_CHOICE)
HTM_INPUT_RADIO (StrAns,false,
"id=\"Ans%010u_%010u\" value=\"%u\""
@@ -3799,9 +3789,7 @@ static void Svy_ReceiveAndStoreUserAnswersToASurvey (long SvyCod)
Lay_ShowErrorAndExit ("Error: wrong question code.");
/* Get possible parameter with the user's answer */
- snprintf (ParamName,sizeof (ParamName),
- "Ans%010u",
- (unsigned) QstCod);
+ snprintf (ParamName,sizeof (ParamName),"Ans%010u",(unsigned) QstCod);
// Lay_ShowAlert (Lay_INFO,ParamName);
Par_GetParMultiToText (ParamName,StrAnswersIndexes,
Svy_MAX_ANSWERS_PER_QUESTION * (Cns_MAX_DECIMAL_DIGITS_UINT + 1));
diff --git a/swad_syllabus.c b/swad_syllabus.c
index 7db89e05..37b1d6b8 100644
--- a/swad_syllabus.c
+++ b/swad_syllabus.c
@@ -118,7 +118,7 @@ static void Syl_ChangePlaceItemSyllabus (Syl_ChangePosItem_t UpOrDownPos);
static void Syl_ChangeLevelItemSyllabus (Syl_ChangeLevelItem_t IncreaseOrDecreaseLevel);
static void Syl_OpenSyllabusFile (const struct Syl_Syllabus *Syllabus,
- char *PathFile);
+ char PathFile[PATH_MAX + 1]);
/*****************************************************************************/
/************************** Reset syllabus context ***************************/
@@ -371,8 +371,7 @@ void Syl_LoadListItemsSyllabusIntoMemory (struct Syl_Syllabus *Syllabus,
unsigned NumItemsWithChildren = 0;
/* Path of the private directory for the XML file with the syllabus */
- snprintf (Syllabus->PathDir,sizeof (Syllabus->PathDir),
- "%s/%ld/%s",
+ snprintf (Syllabus->PathDir,sizeof (Syllabus->PathDir),"%s/%ld/%s",
Cfg_PATH_CRS_PRIVATE,CrsCod,
Syllabus->WhichSyllabus == Syl_LECTURES ? Cfg_SYLLABUS_FOLDER_LECTURES :
Cfg_SYLLABUS_FOLDER_PRACTICALS);
@@ -393,8 +392,8 @@ void Syl_LoadListItemsSyllabusIntoMemory (struct Syl_Syllabus *Syllabus,
Syl_LstItemsSyllabus.NumItems++);
/***** Allocate memory for the list of items *****/
- if ((Syl_LstItemsSyllabus.Lst = (struct ItemSyllabus *) calloc (Syl_LstItemsSyllabus.NumItems + 1,
- sizeof (struct ItemSyllabus))) == NULL)
+ if ((Syl_LstItemsSyllabus.Lst = calloc (Syl_LstItemsSyllabus.NumItems + 1,
+ sizeof (*Syl_LstItemsSyllabus.Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Return to the start of the list *****/
@@ -907,17 +906,13 @@ static void Syl_WriteNumItem (char *StrDst,FILE *FileTgt,int Level,int *CodItem)
if (N > 1)
{
if (StrDst)
- Str_Concat (StrDst,".",
- Syl_MAX_BYTES_ITEM_COD);
+ Str_Concat (StrDst,".",Syl_MAX_BYTES_ITEM_COD);
if (FileTgt)
fprintf (FileTgt,".");
}
- snprintf (InStr,sizeof (InStr),
- "%d",
- CodItem[N]);
+ snprintf (InStr,sizeof (InStr),"%d",CodItem[N]);
if (StrDst)
- Str_Concat (StrDst,InStr,
- Syl_MAX_BYTES_ITEM_COD);
+ Str_Concat (StrDst,InStr,Syl_MAX_BYTES_ITEM_COD);
if (FileTgt)
fprintf (FileTgt,"%s",InStr);
}
@@ -1379,15 +1374,12 @@ void Syl_ModifyItemSyllabus (void)
/*****************************************************************************/
void Syl_BuildPathFileSyllabus (const struct Syl_Syllabus *Syllabus,
- char *PathFile)
+ char PathFile[PATH_MAX + 1])
{
char Path[PATH_MAX + 1 + NAME_MAX + 1];
- snprintf (Path,sizeof (Path),
- "%s/%s",
- Syllabus->PathDir,Cfg_SYLLABUS_FILENAME);
- Str_Copy (PathFile,Path,
- PATH_MAX);
+ snprintf (Path,sizeof (Path),"%s/%s",Syllabus->PathDir,Cfg_SYLLABUS_FILENAME);
+ Str_Copy (PathFile,Path,PATH_MAX);
}
/*****************************************************************************/
@@ -1395,7 +1387,7 @@ void Syl_BuildPathFileSyllabus (const struct Syl_Syllabus *Syllabus,
/*****************************************************************************/
static void Syl_OpenSyllabusFile (const struct Syl_Syllabus *Syllabus,
- char *PathFile)
+ char PathFile[PATH_MAX + 1])
{
if (Gbl.F.XML == NULL) // If it's not open in this moment...
{
diff --git a/swad_syllabus.h b/swad_syllabus.h
index 3fa7936f..4fd4f3f6 100644
--- a/swad_syllabus.h
+++ b/swad_syllabus.h
@@ -111,7 +111,7 @@ void Syl_LeftItemSyllabus (void);
void Syl_InsertItemSyllabus (void);
void Syl_ModifyItemSyllabus (void);
void Syl_BuildPathFileSyllabus (const struct Syl_Syllabus *Syllabus,
- char *PathFile);
+ char PathFile[PATH_MAX + 1]);
void Syl_WriteStartFileSyllabus (FILE *FileSyllabus);
void Syl_WriteAllItemsFileSyllabus (FILE *FileSyllabus);
void Syl_WriteItemFileSyllabus (FILE *FileSyllabus,int Level,const char *Text);
diff --git a/swad_test.c b/swad_test.c
index 0e46702e..819fc9a3 100644
--- a/swad_test.c
+++ b/swad_test.c
@@ -124,7 +124,7 @@ static void TstPrn_GetAnswersFromForm (struct TstPrn_Print *Print);
static bool Tst_CheckIfNextTstAllowed (void);
static unsigned Tst_GetNumExamsGeneratedByMe (void);
-static void Tst_PutFormToEditQstMedia (const struct Med_Media *Media,int NumMediaInForm,
+static void Tst_PutFormToEditQstMedia (const struct Med_Media *Media,int NumMedia,
bool OptionsDisabled);
static void Tst_IncreaseMyNumAccessTst (void);
static void Tst_UpdateLastAccTst (unsigned NumQsts);
@@ -572,9 +572,7 @@ static void TstPrn_GetAnswersFromForm (struct TstPrn_Print *Print)
NumQst++)
{
/* Get answers selected by user for this question */
- snprintf (StrAns,sizeof (StrAns),
- "Ans%010u",
- NumQst);
+ snprintf (StrAns,sizeof (StrAns),"Ans%010u",NumQst);
Par_GetParMultiToText (StrAns,Print->PrintedQuestions[NumQst].StrAnswers,
Tst_MAX_BYTES_ANSWERS_ONE_QST); /* If answer type == T/F ==> " ", "T", "F"; if choice ==> "0", "2",... */
Par_ReplaceSeparatorMultipleByComma (Print->PrintedQuestions[NumQst].StrAnswers);
@@ -816,10 +814,9 @@ void Tst_WriteQstStem (const char *Stem,const char *ClassStem,bool Visible)
{
/* Convert the stem, that is in HTML, to rigorous HTML */
StemLength = strlen (Stem) * Str_MAX_BYTES_PER_CHAR;
- if ((StemRigorousHTML = (char *) malloc (StemLength + 1)) == NULL)
+ if ((StemRigorousHTML = malloc (StemLength + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
- Str_Copy (StemRigorousHTML,Stem,
- StemLength);
+ Str_Copy (StemRigorousHTML,Stem,StemLength);
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
StemRigorousHTML,StemLength,false);
@@ -842,7 +839,7 @@ void Tst_WriteQstStem (const char *Stem,const char *ClassStem,bool Visible)
/************* Put form to upload a new image for a test question ************/
/*****************************************************************************/
-static void Tst_PutFormToEditQstMedia (const struct Med_Media *Media,int NumMediaInForm,
+static void Tst_PutFormToEditQstMedia (const struct Med_Media *Media,int NumMedia,
bool OptionsDisabled)
{
extern const char *The_ClassFormInBox[The_NUM_THEMES];
@@ -855,7 +852,7 @@ static void Tst_PutFormToEditQstMedia (const struct Med_Media *Media,int NumMedi
if (Media->Name[0])
{
/***** Set names of parameters depending on number of image in form *****/
- Med_SetParamNames (&ParamUploadMedia,NumMediaInForm);
+ Med_SetParamNames (&ParamUploadMedia,NumMedia);
/***** Start container *****/
HTM_DIV_Begin ("class=\"TEST_MED_EDIT_FORM\"");
@@ -892,14 +889,14 @@ static void Tst_PutFormToEditQstMedia (const struct Med_Media *Media,int NumMedi
OptionsDisabled ? " disabled=\"disabled\"" : "");
HTM_TxtColonNBSP (Txt_Change_image_video);
HTM_LABEL_End ();
- Med_PutMediaUploader (NumMediaInForm,"TEST_MED_INPUT");
+ Med_PutMediaUploader (NumMedia,"TEST_MED_INPUT");
/***** End container *****/
HTM_DIV_End ();
}
else // No current image
/***** Attached media *****/
- Med_PutMediaUploader (NumMediaInForm,"TEST_MED_INPUT");
+ Med_PutMediaUploader (NumMedia,"TEST_MED_INPUT");
}
/*****************************************************************************/
@@ -916,10 +913,9 @@ void Tst_WriteQstFeedback (const char *Feedback,const char *ClassFeedback)
{
/***** Convert the feedback, that is in HTML, to rigorous HTML *****/
FeedbackLength = strlen (Feedback) * Str_MAX_BYTES_PER_CHAR;
- if ((FeedbackRigorousHTML = (char *) malloc (FeedbackLength + 1)) == NULL)
+ if ((FeedbackRigorousHTML = malloc (FeedbackLength + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
- Str_Copy (FeedbackRigorousHTML,Feedback,
- FeedbackLength);
+ Str_Copy (FeedbackRigorousHTML,Feedback,FeedbackLength);
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
FeedbackRigorousHTML,FeedbackLength,false);
@@ -1481,9 +1477,8 @@ static void Tst_ShowFormConfigTst (void)
/* Data */
HTM_TD_Begin ("class=\"LB\"");
- snprintf (StrMinTimeNxtTstPerQst,sizeof (StrMinTimeNxtTstPerQst),
- "%lu",
- TstCfg_GetConfigMinTimeNxtTstPerQst ());
+ snprintf (StrMinTimeNxtTstPerQst,sizeof (StrMinTimeNxtTstPerQst),"%lu",
+ TstCfg_GetConfigMinTimeNxtTstPerQst ());
HTM_INPUT_TEXT ("MinTimeNxtTstPerQst",Cns_MAX_DECIMAL_DIGITS_ULONG,StrMinTimeNxtTstPerQst,
HTM_DONT_SUBMIT_ON_CHANGE,
"id=\"MinTimeNxtTstPerQst\" size=\"7\" required=\"required\"");
@@ -1537,9 +1532,7 @@ static void Tst_PutInputFieldNumQst (const char *Field,const char *Label,
HTM_TD_End ();
HTM_TD_Begin ("class=\"LM\"");
- snprintf (StrValue,sizeof (StrValue),
- "%u",
- Value);
+ snprintf (StrValue,sizeof (StrValue),"%u",Value);
HTM_INPUT_TEXT (Field,Cns_MAX_DECIMAL_DIGITS_UINT,StrValue,
HTM_DONT_SUBMIT_ON_CHANGE,
"id=\"%s\" size=\"3\" required=\"required\"",Field);
@@ -1750,41 +1743,30 @@ static void Tst_GetQuestions (struct Tst_Test *Test,MYSQL_RES **mysql_res)
char CrsCodStr[Cns_MAX_DECIMAL_DIGITS_LONG + 1];
/***** Allocate space for query *****/
- if ((Query = (char *) malloc (Tst_MAX_BYTES_QUERY_TEST + 1)) == NULL)
+ if ((Query = malloc (Tst_MAX_BYTES_QUERY_TEST + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Select questions *****/
/* Start query */
- snprintf (Query,Tst_MAX_BYTES_QUERY_TEST + 1,
- "SELECT tst_questions.QstCod" // row[0]
- " FROM tst_questions");
+ Str_Copy (Query,"SELECT tst_questions.QstCod" // row[0]
+ " FROM tst_questions",Tst_MAX_BYTES_QUERY_TEST);
if (!Test->Tags.All)
- Str_Concat (Query,",tst_question_tags,tst_tags",
- Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,",tst_question_tags,tst_tags",Tst_MAX_BYTES_QUERY_TEST);
- Str_Concat (Query," WHERE tst_questions.CrsCod='",
- Tst_MAX_BYTES_QUERY_TEST);
- snprintf (CrsCodStr,sizeof (CrsCodStr),
- "%ld",
- Gbl.Hierarchy.Crs.CrsCod);
- Str_Concat (Query,CrsCodStr,
- Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query," WHERE tst_questions.CrsCod='",Tst_MAX_BYTES_QUERY_TEST);
+ snprintf (CrsCodStr,sizeof (CrsCodStr),"%ld",Gbl.Hierarchy.Crs.CrsCod);
+ Str_Concat (Query,CrsCodStr,Tst_MAX_BYTES_QUERY_TEST);
Str_Concat (Query,"' AND tst_questions.EditTime>=FROM_UNIXTIME('",
Tst_MAX_BYTES_QUERY_TEST);
- snprintf (LongStr,sizeof (LongStr),
- "%ld",
- (long) Gbl.DateRange.TimeUTC[Dat_START_TIME]);
- Str_Concat (Query,LongStr,
- Tst_MAX_BYTES_QUERY_TEST);
+ snprintf (LongStr,sizeof (LongStr),"%ld",
+ (long) Gbl.DateRange.TimeUTC[Dat_START_TIME]);
+ Str_Concat (Query,LongStr,Tst_MAX_BYTES_QUERY_TEST);
Str_Concat (Query,"') AND tst_questions.EditTime<=FROM_UNIXTIME('",
Tst_MAX_BYTES_QUERY_TEST);
- snprintf (LongStr,sizeof (LongStr),
- "%ld",
+ snprintf (LongStr,sizeof (LongStr),"%ld",
(long) Gbl.DateRange.TimeUTC[Dat_END_TIME]);
- Str_Concat (Query,LongStr,
- Tst_MAX_BYTES_QUERY_TEST);
- Str_Concat (Query,"')",
- Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,LongStr,Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,"')",Tst_MAX_BYTES_QUERY_TEST);
/* Add the tags selected */
if (!Test->Tags.All)
@@ -1793,10 +1775,8 @@ static void Tst_GetQuestions (struct Tst_Test *Test,MYSQL_RES **mysql_res)
" AND tst_question_tags.TagCod=tst_tags.TagCod"
" AND tst_tags.CrsCod='",
Tst_MAX_BYTES_QUERY_TEST);
- Str_Concat (Query,CrsCodStr,
- Tst_MAX_BYTES_QUERY_TEST);
- Str_Concat (Query,"'",
- Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,CrsCodStr,Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,"'",Tst_MAX_BYTES_QUERY_TEST);
LengthQuery = strlen (Query);
NumItemInList = 0;
Ptr = Test->Tags.List;
@@ -1810,14 +1790,11 @@ static void Tst_GetQuestions (struct Tst_Test *Test,MYSQL_RES **mysql_res)
NumItemInList ? " OR tst_tags.TagTxt='" :
" AND (tst_tags.TagTxt='",
Tst_MAX_BYTES_QUERY_TEST);
- Str_Concat (Query,TagText,
- Tst_MAX_BYTES_QUERY_TEST);
- Str_Concat (Query,"'",
- Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,TagText,Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,"'",Tst_MAX_BYTES_QUERY_TEST);
NumItemInList++;
}
- Str_Concat (Query,")",
- Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,")",Tst_MAX_BYTES_QUERY_TEST);
}
/* Add the types of answer selected */
@@ -1837,19 +1814,15 @@ static void Tst_GetQuestions (struct Tst_Test *Test,MYSQL_RES **mysql_res)
NumItemInList ? " OR tst_questions.AnsType='" :
" AND (tst_questions.AnsType='",
Tst_MAX_BYTES_QUERY_TEST);
- Str_Concat (Query,Tst_StrAnswerTypesDB[AnsType],
- Tst_MAX_BYTES_QUERY_TEST);
- Str_Concat (Query,"'",
- Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,Tst_StrAnswerTypesDB[AnsType],Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,"'",Tst_MAX_BYTES_QUERY_TEST);
NumItemInList++;
}
- Str_Concat (Query,")",
- Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,")",Tst_MAX_BYTES_QUERY_TEST);
}
/* End the query */
- Str_Concat (Query," GROUP BY tst_questions.QstCod",
- Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query," GROUP BY tst_questions.QstCod",Tst_MAX_BYTES_QUERY_TEST);
switch (Test->SelectedOrder)
{
@@ -1915,7 +1888,7 @@ static void Tst_GetQuestionsForNewTestFromDB (struct Tst_Test *Test,
Lay_ShowErrorAndExit ("Wrong number of questions.");
/***** Allocate space for query *****/
- if ((Query = (char *) malloc (Tst_MAX_BYTES_QUERY_TEST + 1)) == NULL)
+ if ((Query = malloc (Tst_MAX_BYTES_QUERY_TEST + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Select questions without hidden tags *****/
@@ -1957,14 +1930,11 @@ static void Tst_GetQuestionsForNewTestFromDB (struct Tst_Test *Test,
NumItemInList ? " OR tst_tags.TagTxt='" :
" AND (tst_tags.TagTxt='",
Tst_MAX_BYTES_QUERY_TEST);
- Str_Concat (Query,TagText,
- Tst_MAX_BYTES_QUERY_TEST);
- Str_Concat (Query,"'",
- Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,TagText,Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,"'",Tst_MAX_BYTES_QUERY_TEST);
NumItemInList++;
}
- Str_Concat (Query,")",
- Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,")",Tst_MAX_BYTES_QUERY_TEST);
}
/* Add answer types selected */
@@ -1984,24 +1954,17 @@ static void Tst_GetQuestionsForNewTestFromDB (struct Tst_Test *Test,
NumItemInList ? " OR tst_questions.AnsType='" :
" AND (tst_questions.AnsType='",
Tst_MAX_BYTES_QUERY_TEST);
- Str_Concat (Query,Tst_StrAnswerTypesDB[AnswerType],
- Tst_MAX_BYTES_QUERY_TEST);
- Str_Concat (Query,"'",
- Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,Tst_StrAnswerTypesDB[AnswerType],Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,"'",Tst_MAX_BYTES_QUERY_TEST);
NumItemInList++;
}
- Str_Concat (Query,")",
- Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query,")",Tst_MAX_BYTES_QUERY_TEST);
}
/* End query */
- Str_Concat (Query," ORDER BY RAND() LIMIT ",
- Tst_MAX_BYTES_QUERY_TEST);
- snprintf (StrNumQsts,sizeof (StrNumQsts),
- "%u",
- Test->NumQsts);
- Str_Concat (Query,StrNumQsts,
- Tst_MAX_BYTES_QUERY_TEST);
+ Str_Concat (Query," ORDER BY RAND() LIMIT ",Tst_MAX_BYTES_QUERY_TEST);
+ snprintf (StrNumQsts,sizeof (StrNumQsts),"%u",Test->NumQsts);
+ Str_Concat (Query,StrNumQsts,Tst_MAX_BYTES_QUERY_TEST);
/*
if (Gbl.Usrs.Me.Roles.LoggedRole == Rol_SYS_ADM)
Lay_ShowAlert (Lay_INFO,Query);
@@ -2115,12 +2078,10 @@ void Tst_GenerateChoiceIndexes (struct TstPrn_PrintedQuestion *PrintedQuestion,
if (ErrorInIndex)
Lay_ShowErrorAndExit ("Wrong index of answer.");
- if (NumOpt == 0)
- snprintf (StrInd,sizeof (StrInd),"%u",Index);
- else
- snprintf (StrInd,sizeof (StrInd),",%u",Index);
+ snprintf (StrInd,sizeof (StrInd),NumOpt ? ",%u" :
+ "%u",Index);
Str_Concat (PrintedQuestion->StrIndexes,StrInd,
- Tst_MAX_BYTES_INDEXES_ONE_QST);
+ sizeof (PrintedQuestion->StrIndexes) - 1);
}
/***** Free structure that stores the query result *****/
@@ -2920,9 +2881,7 @@ void Tst_WriteParamQstCod (unsigned NumQst,long QstCod)
{
char StrAns[3 + Cns_MAX_DECIMAL_DIGITS_UINT + 1]; // "Ansxx...x"
- snprintf (StrAns,sizeof (StrAns),
- "Qst%010u",
- NumQst);
+ snprintf (StrAns,sizeof (StrAns),"Qst%010u",NumQst);
Par_PutHiddenParamLong (NULL,StrAns,QstCod);
}
@@ -3011,7 +2970,7 @@ static bool Tst_GetParamsTst (struct Tst_Test *Test,
Test->Tags.All = Par_GetParToBool ("AllTags");
/* Get the tags */
- if ((Test->Tags.List = (char *) malloc (Tag_MAX_BYTES_TAGS_LIST + 1)) == NULL)
+ if ((Test->Tags.List = malloc (Tag_MAX_BYTES_TAGS_LIST + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
Par_GetParMultiToText ("ChkTag",Test->Tags.List,Tag_MAX_BYTES_TAGS_LIST);
@@ -3044,8 +3003,7 @@ static bool Tst_GetParamsTst (struct Tst_Test *Test,
case Tst_SELECT_QUESTIONS_FOR_GAME:
/* The unique allowed type of answer in a game is unique choice */
Test->AnswerTypes.All = false;
- snprintf (Test->AnswerTypes.List,sizeof (Test->AnswerTypes.List),
- "%u",
+ snprintf (Test->AnswerTypes.List,sizeof (Test->AnswerTypes.List),"%u",
(unsigned) Tst_ANS_UNIQUE_CHOICE);
break;
default:
@@ -3349,9 +3307,7 @@ static void Tst_PutFormEditOneQst (struct Tst_Question *Question)
/***** Input of a new tag *****/
HTM_TD_Begin ("class=\"RM\"");
- snprintf (StrTagTxt,sizeof (StrTagTxt),
- "TagTxt%u",
- IndTag);
+ snprintf (StrTagTxt,sizeof (StrTagTxt),"TagTxt%u",IndTag);
HTM_INPUT_TEXT (StrTagTxt,Tag_MAX_CHARS_TAG,Question->Tags.Txt[IndTag],
HTM_DONT_SUBMIT_ON_CHANGE,
"id=\"%s\" class=\"TAG_TXT\" onchange=\"changeSelTag('%u')\"",
@@ -3435,9 +3391,7 @@ static void Tst_PutFormEditOneQst (struct Tst_Question *Question)
HTM_TD_Begin ("class=\"LT\"");
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
HTM_TxtColonNBSP (Txt_Integer_number);
- snprintf (StrInteger,sizeof (StrInteger),
- "%ld",
- Question->Answer.Integer);
+ snprintf (StrInteger,sizeof (StrInteger),"%ld",Question->Answer.Integer);
HTM_INPUT_TEXT ("AnsInt",Cns_MAX_DECIMAL_DIGITS_LONG,StrInteger,
HTM_DONT_SUBMIT_ON_CHANGE,
"size=\"11\" required=\"required\"%s",
@@ -3643,8 +3597,7 @@ static void Tst_PutFloatInputField (const char *Label,const char *Field,
HTM_LABEL_Begin ("class=\"%s\"",The_ClassFormInBox[Gbl.Prefs.Theme]);
HTM_TxtF ("%s ",Label);
- snprintf (StrDouble,sizeof (StrDouble),
- "%.15lg",
+ snprintf (StrDouble,sizeof (StrDouble),"%.15lg",
Question->Answer.FloatingPoint[Index]);
HTM_INPUT_TEXT (Field,Tst_MAX_BYTES_FLOAT_ANSWER,StrDouble,
HTM_DONT_SUBMIT_ON_CHANGE,
@@ -3690,11 +3643,11 @@ void Tst_QstConstructor (struct Tst_Question *Question)
Question->EditTime = (time_t) 0;
/***** Allocate memory for stem and feedback *****/
- if ((Question->Stem = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
+ if ((Question->Stem = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
Question->Stem[0] = '\0';
- if ((Question->Feedback = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
+ if ((Question->Feedback = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
Question->Feedback[0] = '\0';
@@ -3760,14 +3713,14 @@ void Tst_QstDestructor (struct Tst_Question *Question)
bool Tst_AllocateTextChoiceAnswer (struct Tst_Question *Question,unsigned NumOpt)
{
if ((Question->Answer.Options[NumOpt].Text =
- (char *) malloc (Tst_MAX_BYTES_ANSWER_OR_FEEDBACK + 1)) == NULL)
+ malloc (Tst_MAX_BYTES_ANSWER_OR_FEEDBACK + 1)) == NULL)
{
Ale_CreateAlert (Ale_ERROR,NULL,
"Not enough memory to store answer.");
return false;
}
if ((Question->Answer.Options[NumOpt].Feedback =
- (char *) malloc (Tst_MAX_BYTES_ANSWER_OR_FEEDBACK + 1)) == NULL)
+ malloc (Tst_MAX_BYTES_ANSWER_OR_FEEDBACK + 1)) == NULL)
{
Ale_CreateAlert (Ale_ERROR,NULL,
"Not enough memory to store feedback.");
@@ -3919,15 +3872,13 @@ bool Tst_GetQstDataFromDB (struct Tst_Question *Question)
Question->Stem[0] = '\0';
if (row[3])
if (row[3][0])
- Str_Copy (Question->Stem,row[3],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Question->Stem,row[3],Cns_MAX_BYTES_TEXT);
/* Get the feedback (row[4]) */
Question->Feedback[0] = '\0';
if (row[4])
if (row[4][0])
- Str_Copy (Question->Feedback,row[4],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Question->Feedback,row[4],Cns_MAX_BYTES_TEXT);
/* Get media (row[5]) */
Question->Media.MedCod = Str_ConvertStrCodToLongCod (row[5]);
@@ -3962,7 +3913,7 @@ bool Tst_GetQstDataFromDB (struct Tst_Question *Question)
{
row = mysql_fetch_row (mysql_res);
Str_Copy (Question->Tags.Txt[NumRow],row[0],
- Tag_MAX_BYTES_TAG);
+ sizeof (Question->Tags.Txt[NumRow]) - 1);
}
/* Free structure that stores the query result */
@@ -4164,8 +4115,7 @@ void Tst_ReceiveQst (void)
Tst_InsertOrUpdateQstTagsAnsIntoDB (&Test.Question);
/***** Show the question just inserted in the database *****/
- snprintf (Test.AnswerTypes.List,sizeof (Test.AnswerTypes.List),
- "%u",
+ snprintf (Test.AnswerTypes.List,sizeof (Test.AnswerTypes.List),"%u",
(unsigned) Test.Question.Answer.Type);
Tst_ListOneQstToEdit (&Test);
}
@@ -4217,9 +4167,7 @@ static void Tst_GetQstFromForm (struct Tst_Question *Question)
NumTag < Tag_MAX_TAGS_PER_QUESTION;
NumTag++)
{
- snprintf (TagStr,sizeof (TagStr),
- "TagTxt%u",
- NumTag);
+ snprintf (TagStr,sizeof (TagStr),"TagTxt%u",NumTag);
Par_GetParToText (TagStr,Question->Tags.Txt[NumTag],Tag_MAX_BYTES_TAG);
if (Question->Tags.Txt[NumTag][0])
@@ -4303,9 +4251,7 @@ static void Tst_GetQstFromForm (struct Tst_Question *Question)
Ale_ShowAlertsAndExit ();
/* Get answer */
- snprintf (AnsStr,sizeof (AnsStr),
- "AnsStr%u",
- NumOpt);
+ snprintf (AnsStr,sizeof (AnsStr),"AnsStr%u",NumOpt);
Par_GetParToHTML (AnsStr,Question->Answer.Options[NumOpt].Text,
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK);
if (Question->Answer.Type == Tst_ANS_TEXT)
@@ -4314,9 +4260,7 @@ static void Tst_GetQstFromForm (struct Tst_Question *Question)
Str_ReplaceSeveralSpacesForOne (Question->Answer.Options[NumOpt].Text);
/* Get feedback */
- snprintf (FbStr,sizeof (FbStr),
- "FbStr%u",
- NumOpt);
+ snprintf (FbStr,sizeof (FbStr),"FbStr%u",NumOpt);
Par_GetParToHTML (FbStr,Question->Answer.Options[NumOpt].Feedback,
Tst_MAX_BYTES_ANSWER_OR_FEEDBACK);
diff --git a/swad_test_import.c b/swad_test_import.c
index cc058cb6..bc2c9fff 100644
--- a/swad_test_import.c
+++ b/swad_test_import.c
@@ -197,8 +197,7 @@ void TsI_CreateXML (unsigned NumQsts,MYSQL_RES *mysql_res)
Brw_CreateDirDownloadTmp ();
/***** Create public XML file with the questions *****/
- snprintf (PathPubFile,sizeof (PathPubFile),
- "%s/%s/%s/test.xml",
+ snprintf (PathPubFile,sizeof (PathPubFile),"%s/%s/%s/test.xml",
Cfg_PATH_FILE_BROWSER_TMP_PUBLIC,
Gbl.FileBrowser.TmpPubDir.L,
Gbl.FileBrowser.TmpPubDir.R);
@@ -424,8 +423,7 @@ void TsI_ImportQstsFromXML (void)
else
{
/* End the reception of XML in a temporary file */
- snprintf (FileNameXMLTmp,sizeof (FileNameXMLTmp),
- "%s/%s.xml",
+ snprintf (FileNameXMLTmp,sizeof (FileNameXMLTmp),"%s/%s.xml",
Cfg_PATH_TEST_PRIVATE,Gbl.UniqueNameEncrypted);
if (Fil_EndReceptionOfFile (FileNameXMLTmp,Param))
/***** Get questions from XML file and store them in database *****/
@@ -455,7 +453,7 @@ static void TsI_ReadQuestionsFromXMLFileAndStoreInDB (const char *FileNameXML)
fseek (FileXML,0L,SEEK_SET);
/***** Allocate memory for XML buffer *****/
- if ((XMLBuffer = (char *) malloc (FileSize + 1)) == NULL)
+ if ((XMLBuffer = malloc (FileSize + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
else
{
@@ -569,7 +567,7 @@ static void TsI_ImportQuestionsFromXMLBuffer (const char *XMLBuffer)
{
Str_Copy (Question.Tags.Txt[Question.Tags.Num],
TagElem->Content,
- Tag_MAX_BYTES_TAG);
+ sizeof (Question.Tags.Txt[Question.Tags.Num]) - 1);
Question.Tags.Num++;
}
}
@@ -585,8 +583,7 @@ static void TsI_ImportQuestionsFromXMLBuffer (const char *XMLBuffer)
if (StemElem->Content)
{
/* Convert stem from text to HTML (in database stem is stored in HTML) */
- Str_Copy (Question.Stem,StemElem->Content,
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Question.Stem,StemElem->Content,Cns_MAX_BYTES_TEXT);
Str_ChangeFormat (Str_FROM_TEXT,Str_TO_HTML,
Question.Stem,Cns_MAX_BYTES_TEXT,true);
}
@@ -602,8 +599,7 @@ static void TsI_ImportQuestionsFromXMLBuffer (const char *XMLBuffer)
if (FeedbackElem->Content)
{
/* Convert feedback from text to HTML (in database feedback is stored in HTML) */
- Str_Copy (Question.Feedback,FeedbackElem->Content,
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Question.Feedback,FeedbackElem->Content,Cns_MAX_BYTES_TEXT);
Str_ChangeFormat (Str_FROM_TEXT,Str_TO_HTML,
Question.Feedback,Cns_MAX_BYTES_TEXT,true);
}
@@ -1004,7 +1000,7 @@ static void TsI_WriteRowImportedQst (struct XMLElement *StemElem,
/* Convert the answer, that is in HTML, to rigorous HTML */
AnswerTextLength = strlen (Question->Answer.Options[NumOpt].Text) *
Str_MAX_BYTES_PER_CHAR;
- if ((AnswerText = (char *) malloc (AnswerTextLength + 1)) == NULL)
+ if ((AnswerText = malloc (AnswerTextLength + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
Str_Copy (AnswerText,Question->Answer.Options[NumOpt].Text,
AnswerTextLength);
@@ -1019,7 +1015,7 @@ static void TsI_WriteRowImportedQst (struct XMLElement *StemElem,
{
AnswerFeedbackLength = strlen (Question->Answer.Options[NumOpt].Feedback) *
Str_MAX_BYTES_PER_CHAR;
- if ((AnswerFeedback = (char *) malloc (AnswerFeedbackLength + 1)) == NULL)
+ if ((AnswerFeedback = malloc (AnswerFeedbackLength + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
Str_Copy (AnswerFeedback,
Question->Answer.Options[NumOpt].Feedback,
diff --git a/swad_test_print.c b/swad_test_print.c
index 08a76441..6787dfac 100644
--- a/swad_test_print.c
+++ b/swad_test_print.c
@@ -413,9 +413,7 @@ static void TstPrn_WriteIntAnsToFill (const struct TstPrn_PrintedQuestion *Print
char StrAns[3 + Cns_MAX_DECIMAL_DIGITS_UINT + 1]; // "Ansxx...x"
/***** Write input field for the answer *****/
- snprintf (StrAns,sizeof (StrAns),
- "Ans%010u",
- NumQst);
+ snprintf (StrAns,sizeof (StrAns),"Ans%010u",NumQst);
HTM_INPUT_TEXT (StrAns,11,PrintedQuestion->StrAnswers,
HTM_DONT_SUBMIT_ON_CHANGE,
"size=\"11\"");
@@ -432,9 +430,7 @@ static void TstPrn_WriteFltAnsToFill (const struct TstPrn_PrintedQuestion *Print
char StrAns[3 + Cns_MAX_DECIMAL_DIGITS_UINT + 1]; // "Ansxx...x"
/***** Write input field for the answer *****/
- snprintf (StrAns,sizeof (StrAns),
- "Ans%010u",
- NumQst);
+ snprintf (StrAns,sizeof (StrAns),"Ans%010u",NumQst);
HTM_INPUT_TEXT (StrAns,Tst_MAX_BYTES_FLOAT_ANSWER,PrintedQuestion->StrAnswers,
HTM_DONT_SUBMIT_ON_CHANGE,
"size=\"11\"");
@@ -501,9 +497,7 @@ static void TstPrn_WriteChoAnsToFill (const struct TstPrn_PrintedQuestion *Print
==> the exam may be half filled ==> the answers displayed will be those selected by the user. */
HTM_TD_Begin ("class=\"LT\"");
- snprintf (StrAns,sizeof (StrAns),
- "Ans%010u",
- NumQst);
+ snprintf (StrAns,sizeof (StrAns),"Ans%010u",NumQst);
if (Question->Answer.Type == Tst_ANS_UNIQUE_CHOICE)
HTM_INPUT_RADIO (StrAns,false,
"id=\"Ans%010u_%u\" value=\"%u\"%s"
@@ -557,9 +551,7 @@ static void TstPrn_WriteTxtAnsToFill (const struct TstPrn_PrintedQuestion *Print
char StrAns[3 + Cns_MAX_DECIMAL_DIGITS_UINT + 1]; // "Ansxx...x"
/***** Write input field for the answer *****/
- snprintf (StrAns,sizeof (StrAns),
- "Ans%010u",
- NumQst);
+ snprintf (StrAns,sizeof (StrAns),"Ans%010u",NumQst);
HTM_INPUT_TEXT (StrAns,Tst_MAX_CHARS_ANSWERS_ONE_QST,PrintedQuestion->StrAnswers,
HTM_DONT_SUBMIT_ON_CHANGE,
"size=\"40\"");
@@ -1214,8 +1206,7 @@ void TstPrn_ComputeTxtAnsScore (struct TstPrn_PrintedQuestion *PrintedQuestion,
if (PrintedQuestion->StrAnswers[0]) // If user has answered the answer
{
/* Filter the user answer */
- Str_Copy (TextAnsUsr,PrintedQuestion->StrAnswers,
- Tst_MAX_BYTES_ANSWERS_ONE_QST);
+ Str_Copy (TextAnsUsr,PrintedQuestion->StrAnswers,sizeof (TextAnsUsr) - 1);
/* In order to compare student answer to stored answer,
the text answers are stored avoiding two or more consecurive spaces */
@@ -1228,8 +1219,7 @@ void TstPrn_ComputeTxtAnsScore (struct TstPrn_PrintedQuestion *PrintedQuestion,
NumOpt++)
{
/* Filter this correct answer */
- Str_Copy (TextAnsOK,Question->Answer.Options[NumOpt].Text,
- Tst_MAX_BYTES_ANSWERS_ONE_QST);
+ Str_Copy (TextAnsOK,Question->Answer.Options[NumOpt].Text,sizeof (TextAnsOK) - 1);
Str_ConvertToComparable (TextAnsOK);
/* Check is user answer is correct */
@@ -1728,8 +1718,7 @@ static void TstPrn_WriteTxtAnsPrint (struct UsrData *UsrDat,
if (PrintedQuestion->StrAnswers[0]) // If user has answered the question
{
/* Filter the user answer */
- Str_Copy (TextAnsUsr,PrintedQuestion->StrAnswers,
- Tst_MAX_BYTES_ANSWERS_ONE_QST);
+ Str_Copy (TextAnsUsr,PrintedQuestion->StrAnswers,sizeof (TextAnsUsr) - 1);
/* In order to compare student answer to stored answer,
the text answers are stored avoiding two or more consecurive spaces */
@@ -1742,8 +1731,7 @@ static void TstPrn_WriteTxtAnsPrint (struct UsrData *UsrDat,
NumOpt++)
{
/* Filter this correct answer */
- Str_Copy (TextAnsOK,Question->Answer.Options[NumOpt].Text,
- Tst_MAX_BYTES_ANSWERS_ONE_QST);
+ Str_Copy (TextAnsOK,Question->Answer.Options[NumOpt].Text,sizeof (TextAnsOK) - 1);
Str_ConvertToComparable (TextAnsOK);
/* Check is user answer is correct */
@@ -1976,7 +1964,7 @@ static void TstPrn_ShowUsrsPrints (__attribute__((unused)) void *Args)
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,Gbl.Usrs.Other.UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&Gbl.Usrs.Other.UsrDat);
if (Usr_ChkUsrCodAndGetAllUsrDataFromUsrCod (&Gbl.Usrs.Other.UsrDat,Usr_DONT_GET_PREFS))
@@ -2451,8 +2439,8 @@ void TstPrn_ShowOnePrint (void)
HTM_TxtF (" %s",Gbl.Usrs.Other.UsrDat.Surname1);
if (Gbl.Usrs.Other.UsrDat.Surname2[0])
HTM_TxtF (" %s",Gbl.Usrs.Other.UsrDat.Surname2);
- if (Gbl.Usrs.Other.UsrDat.FirstName[0])
- HTM_TxtF (", %s",Gbl.Usrs.Other.UsrDat.FirstName);
+ if (Gbl.Usrs.Other.UsrDat.FrstName[0])
+ HTM_TxtF (", %s",Gbl.Usrs.Other.UsrDat.FrstName);
HTM_BR ();
ShowPhoto = Pho_ShowingUsrPhotoIsAllowed (&Gbl.Usrs.Other.UsrDat,PhotoURL);
Pho_ShowUsrPhoto (&Gbl.Usrs.Other.UsrDat,ShowPhoto ? PhotoURL :
@@ -2799,11 +2787,11 @@ void TstPrn_GetPrintQuestionsFromDB (struct TstPrn_Print *Print)
/* Get indexes for this question (row[2]) */
Str_Copy (Print->PrintedQuestions[NumQst].StrIndexes,row[2],
- Tst_MAX_BYTES_INDEXES_ONE_QST);
+ sizeof (Print->PrintedQuestions[NumQst].StrIndexes) - 1);
/* Get answers selected by user for this question (row[3]) */
Str_Copy (Print->PrintedQuestions[NumQst].StrAnswers,row[3],
- Tst_MAX_BYTES_ANSWERS_ONE_QST);
+ sizeof (Print->PrintedQuestions[NumQst].StrAnswers) - 1);
}
/***** Free structure that stores the query result *****/
diff --git a/swad_test_visibility.c b/swad_test_visibility.c
index 94a4376e..5d24f30e 100644
--- a/swad_test_visibility.c
+++ b/swad_test_visibility.c
@@ -155,7 +155,7 @@ unsigned TstVis_GetVisibilityFromForm (void)
/***** Allocate memory for list of attendance events selected *****/
MaxSizeListVisibilitySelected = TstVis_NUM_ITEMS_VISIBILITY * (Cns_MAX_DECIMAL_DIGITS_UINT + 1);
- if ((StrVisibilitySelected = (char *) malloc (MaxSizeListVisibilitySelected + 1)) == NULL)
+ if ((StrVisibilitySelected = malloc (MaxSizeListVisibilitySelected + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Get parameter multiple with list of visibility items selected *****/
diff --git a/swad_theme.c b/swad_theme.c
index af3e5460..3ca87b62 100644
--- a/swad_theme.c
+++ b/swad_theme.c
@@ -331,10 +331,8 @@ void The_PutIconsToSelectTheme (void)
"PREF_OFF");
Frm_StartForm (ActChgThe);
Par_PutHiddenParamString (NULL,"Theme",The_ThemeId[Theme]);
- snprintf (Icon,sizeof (Icon),
- "%s/%s/theme_32x20.gif",
- Cfg_ICON_FOLDER_THEMES,
- The_ThemeId[Theme]);
+ snprintf (Icon,sizeof (Icon),"%s/%s/theme_32x20.gif",
+ Cfg_ICON_FOLDER_THEMES,The_ThemeId[Theme]);
Ico_PutSettingIconLink (Icon,The_ThemeNames[Theme]);
Frm_EndForm ();
HTM_DIV_End ();
@@ -366,12 +364,9 @@ void The_ChangeTheme (void)
/***** Get param theme *****/
Gbl.Prefs.Theme = The_GetParamTheme ();
- snprintf (Path,sizeof (Path),
- "%s/%s",
- Cfg_URL_ICON_THEMES_PUBLIC,
- The_ThemeId[Gbl.Prefs.Theme]);
- Str_Copy (Gbl.Prefs.URLTheme,Path,
- PATH_MAX);
+ snprintf (Path,sizeof (Path),"%s/%s",
+ Cfg_URL_ICON_THEMES_PUBLIC,The_ThemeId[Gbl.Prefs.Theme]);
+ Str_Copy (Gbl.Prefs.URLTheme,Path,sizeof (Gbl.Prefs.URLTheme) - 1);
/***** Store theme in database *****/
if (Gbl.Usrs.Me.Logged)
diff --git a/swad_timeline.c b/swad_timeline.c
index 4a769c3b..be3800c9 100644
--- a/swad_timeline.c
+++ b/swad_timeline.c
@@ -296,7 +296,7 @@ void TL_ShowTimelineUsrHighlightingNot (struct TL_Timeline *Timeline,
/***** Show timeline *****/
TL_ShowTimeline (Timeline,
Str_BuildStringStr (Txt_Timeline_OF_A_USER,
- Gbl.Usrs.Other.UsrDat.FirstName),
+ Gbl.Usrs.Other.UsrDat.FrstName),
NotCod);
Str_FreeString ();
@@ -515,7 +515,7 @@ void TL_FormStart (const struct TL_Timeline *Timeline,
{
/***** Start form in user timeline *****/
Frm_StartFormAnchor (ActionUsr,"timeline");
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
}
else
{
diff --git a/swad_timeline_comment.c b/swad_timeline_comment.c
index 4ff154dc..11588445 100644
--- a/swad_timeline_comment.c
+++ b/swad_timeline_comment.c
@@ -28,7 +28,6 @@
#define _GNU_SOURCE // For asprintf
#include // For PATH_MAX
#include // For asprintf
-#include // For malloc and free
#include "swad_database.h"
#include "swad_forum.h"
@@ -347,7 +346,7 @@ static void TL_Com_FormToShowHiddenComments (Act_Action_t ActionGbl,Act_Action_t
NotCod,
IdComments,
NumInitialComments,
- Gbl.Usrs.Other.UsrDat.EncryptedUsrCod) < 0)
+ Gbl.Usrs.Other.UsrDat.EnUsrCod) < 0)
Lay_NotEnoughMemoryExit ();
Frm_StartFormUniqueAnchorOnSubmit (ActUnk,"timeline",OnSubmit);
}
@@ -678,7 +677,7 @@ static void TL_Com_WriteAuthorComment (struct UsrData *UsrDat)
/***** Show user's name inside form to go to user's public profile *****/
Frm_StartFormUnique (ActSeeOthPubPrf);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_BUTTON_SUBMIT_Begin (ItsMe ? Txt_My_public_profile :
Txt_Another_user_s_profile,
"BT_LINK TL_COM_AUTHOR TL_COMM_AUTHOR_WIDTH DAT_BOLD",NULL);
@@ -915,7 +914,7 @@ static void TL_Com_PutParamsRemoveComment (void *Timeline)
if (Timeline)
{
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
else
Usr_PutHiddenParamWho (((struct TL_Timeline *) Timeline)->Who);
TL_Pub_PutHiddenParamPubCod (((struct TL_Timeline *) Timeline)->PubCod);
@@ -1127,8 +1126,7 @@ static void TL_Com_GetDataOfCommentFromRow (MYSQL_ROW row,struct TL_Com_Comment
Com->DateTimeUTC = Dat_GetUNIXTimeFromStr (row[3]);
/***** Get text content (row[4]) *****/
- Str_Copy (Com->Content.Txt,row[4],
- Cns_MAX_BYTES_LONG_TEXT);
+ Str_Copy (Com->Content.Txt,row[4],sizeof (Com->Content.Txt) - 1);
/***** Get number of times this comment has been favourited *****/
TL_Fav_GetNumTimesACommHasBeenFav (Com);
diff --git a/swad_timeline_note.c b/swad_timeline_note.c
index 65b2a0e1..f5afa81b 100644
--- a/swad_timeline_note.c
+++ b/swad_timeline_note.c
@@ -389,7 +389,7 @@ static void TL_Not_WriteTopMessage (TL_TopMessage_t TopMessage,long PublisherCod
/***** Show user's name inside form to go to user's public profile *****/
Frm_StartFormUnique (ActSeeOthPubPrf);
- Usr_PutParamUsrCodEncrypted (PublisherDat.EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (PublisherDat.EnUsrCod);
HTM_BUTTON_SUBMIT_Begin (ItsMe ? Txt_My_public_profile :
Txt_Another_user_s_profile,
"BT_LINK TL_TOP_PUBLISHER",NULL);
@@ -419,7 +419,7 @@ void TL_Not_WriteAuthorNote (const struct UsrData *UsrDat)
/***** Show user's name inside form to go to user's public profile *****/
Frm_StartFormUnique (ActSeeOthPubPrf);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_BUTTON_SUBMIT_Begin (ItsMe ? Txt_My_public_profile :
Txt_Another_user_s_profile,
"BT_LINK TL_RIGHT_AUTHOR TL_RIGHT_AUTHOR_WIDTH DAT_N_BOLD",
@@ -1064,7 +1064,7 @@ static void TL_Not_PutParamsRemoveNote (void *Timeline)
if (Timeline)
{
if (Gbl.Usrs.Other.UsrDat.UsrCod > 0)
- Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EncryptedUsrCod);
+ Usr_PutParamOtherUsrCodEncrypted (Gbl.Usrs.Other.UsrDat.EnUsrCod);
else
Usr_PutHiddenParamWho (((struct TL_Timeline *) Timeline)->Who);
TL_Not_PutHiddenParamNotCod (((struct TL_Timeline *) Timeline)->NotCod);
@@ -1350,7 +1350,7 @@ long TL_Not_GetPubCodOfOriginalNote (long NotCod)
/****** Add just retrieved notes to current timeline for this session ********/
/*****************************************************************************/
-void TL_Not_AddNotesJustRetrievedToTimelineThisSession (void)
+void TL_Not_AddNotesJustRetrievedToVisibleTimelineThisSession (void)
{
/* tl_timelines contains the distinct notes in timeline of each open session:
mysql> SELECT SessionId,COUNT(*) FROM tl_timelines GROUP BY SessionId;
diff --git a/swad_timeline_note.h b/swad_timeline_note.h
index 74309dfe..1780bdae 100644
--- a/swad_timeline_note.h
+++ b/swad_timeline_note.h
@@ -117,7 +117,7 @@ void TL_Not_RemoveNoteGbl (void);
long TL_Not_GetPubCodOfOriginalNote (long NotCod);
-void TL_Not_AddNotesJustRetrievedToTimelineThisSession (void);
+void TL_Not_AddNotesJustRetrievedToVisibleTimelineThisSession (void);
void TL_Not_GetDataOfNoteByCod (struct TL_Not_Note *Not);
diff --git a/swad_timeline_notification.c b/swad_timeline_notification.c
index 79929908..6313fbb8 100644
--- a/swad_timeline_notification.c
+++ b/swad_timeline_notification.c
@@ -156,8 +156,7 @@ void TL_Ntf_GetNotifPublication (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
row = mysql_fetch_row (mysql_res);
/****** Get content (row[0]) *****/
- Str_Copy (Content.Txt,row[0],
- Cns_MAX_BYTES_LONG_TEXT);
+ Str_Copy (Content.Txt,row[0],sizeof (Content.Txt) - 1);
}
/***** Free structure that stores the query result *****/
@@ -167,18 +166,16 @@ void TL_Ntf_GetNotifPublication (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
if (GetContent)
{
Length = strlen (Content.Txt);
- if ((*ContentStr = (char *) malloc (Length + 1)) != NULL)
+ if ((*ContentStr = malloc (Length + 1)) != NULL)
{
- Str_Copy (*ContentStr,Content.Txt,
- Length);
+ Str_Copy (*ContentStr,Content.Txt,Length);
ContentCopied = true;
}
}
/***** Copy summary string *****/
Str_LimitLengthHTMLStr (Content.Txt,Ntf_MAX_CHARS_SUMMARY);
- Str_Copy (SummaryStr,Content.Txt,
- Ntf_MAX_BYTES_SUMMARY);
+ Str_Copy (SummaryStr,Content.Txt,Ntf_MAX_BYTES_SUMMARY);
}
else
TL_Not_GetNoteSummary (&Not,SummaryStr);
@@ -196,8 +193,7 @@ void TL_Ntf_GetNotifPublication (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
row = mysql_fetch_row (mysql_res);
/****** Get content (row[0]) *****/
- Str_Copy (Content.Txt,row[0],
- Cns_MAX_BYTES_LONG_TEXT);
+ Str_Copy (Content.Txt,row[0],sizeof (Content.Txt) - 1);
}
/***** Free structure that stores the query result *****/
@@ -207,24 +203,22 @@ void TL_Ntf_GetNotifPublication (char SummaryStr[Ntf_MAX_BYTES_SUMMARY + 1],
if (GetContent)
{
Length = strlen (Content.Txt);
- if ((*ContentStr = (char *) malloc (Length + 1)) != NULL)
+ if ((*ContentStr = malloc (Length + 1)) != NULL)
{
- Str_Copy (*ContentStr,Content.Txt,
- Length);
+ Str_Copy (*ContentStr,Content.Txt,Length);
ContentCopied = true;
}
}
/***** Copy summary string *****/
Str_LimitLengthHTMLStr (Content.Txt,Ntf_MAX_CHARS_SUMMARY);
- Str_Copy (SummaryStr,Content.Txt,
- Ntf_MAX_BYTES_SUMMARY);
+ Str_Copy (SummaryStr,Content.Txt,Ntf_MAX_BYTES_SUMMARY);
break;
}
/***** Create empty content string if nothing copied *****/
if (GetContent && !ContentCopied)
- if ((*ContentStr = (char *) malloc (1)) != NULL)
+ if ((*ContentStr = malloc (1)) != NULL)
(*ContentStr)[0] = '\0';
}
diff --git a/swad_timeline_post.c b/swad_timeline_post.c
index 518c57fa..9dd22dc1 100644
--- a/swad_timeline_post.c
+++ b/swad_timeline_post.c
@@ -91,8 +91,7 @@ void TL_Pst_GetAndWritePost (long PstCod)
row = mysql_fetch_row (mysql_res);
/****** Get content (row[0]) *****/
- Str_Copy (Content.Txt,row[0],
- Cns_MAX_BYTES_LONG_TEXT);
+ Str_Copy (Content.Txt,row[0],sizeof (Content.Txt) - 1);
/***** Get media (row[1]) *****/
Content.Media.MedCod = Str_ConvertStrCodToLongCod (row[1]);
diff --git a/swad_timeline_publication.c b/swad_timeline_publication.c
index bb76bfc9..d425387b 100644
--- a/swad_timeline_publication.c
+++ b/swad_timeline_publication.c
@@ -235,8 +235,8 @@ void TL_Pub_GetListPubsToShowInTimeline (struct TL_Timeline *Timeline)
into session for next refresh *****/
TL_Pub_UpdateFirstLastPubCodesIntoSession (Timeline);
- /***** Add notes just retrieved to current timeline for this session *****/
- TL_Not_AddNotesJustRetrievedToTimelineThisSession ();
+ /***** Add notes just retrieved to visible timeline for this session *****/
+ TL_Not_AddNotesJustRetrievedToVisibleTimelineThisSession ();
/***** Drop temporary tables *****/
TL_Pub_DropTemporaryTables (Timeline);
@@ -304,7 +304,7 @@ static void TL_Pub_CreateSubQueryPublishers (const struct TL_Timeline *Timeline,
SubQueries->TablePublishers = ",fol_tmp_me_and_followed";
Str_Copy (SubQueries->Publishers,
"tl_pubs.PublisherCod=fol_tmp_me_and_followed.UsrCod AND ",
- TL_Pub_MAX_BYTES_SUBQUERY);
+ sizeof (SubQueries->Publishers) - 1);
break;
case Usr_WHO_ALL: // Show the timeline of all users
SubQueries->TablePublishers = "";
@@ -332,13 +332,13 @@ static void TL_Pub_CreateSubQueryAlreadyExists (const struct TL_Timeline *Timeli
Str_Copy (SubQueries->AlreadyExists,
" tl_pubs.NotCod NOT IN"
" (SELECT NotCod FROM tl_tmp_just_retrieved_notes)", // Avoid notes just retrieved
- TL_Pub_MAX_BYTES_SUBQUERY);
+ sizeof (SubQueries->AlreadyExists) - 1);
break;
case TL_GET_ONLY_OLD_PUBS: // Get only old publications
Str_Copy (SubQueries->AlreadyExists,
" tl_pubs.NotCod NOT IN"
" (SELECT NotCod FROM tl_tmp_visible_timeline)", // Avoid notes already shown
- TL_Pub_MAX_BYTES_SUBQUERY);
+ sizeof (SubQueries->AlreadyExists) - 1);
break;
}
}
@@ -503,8 +503,8 @@ static struct TL_Pub_Publication *TL_Pub_SelectTheMostRecentPub (const struct TL
if (NumPubs == 1)
{
/* Allocate space for publication */
- if ((Pub = (struct TL_Pub_Publication *) malloc (sizeof (struct TL_Pub_Publication))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory publication.");
+ if ((Pub = malloc (sizeof (*Pub))) == NULL)
+ Lay_NotEnoughMemoryExit ();
/* Get data of publication */
TL_Pub_GetDataOfPublicationFromNextRow (mysql_res,Pub);
diff --git a/swad_timeline_user.c b/swad_timeline_user.c
index c8d09689..d7c3b3df 100644
--- a/swad_timeline_user.c
+++ b/swad_timeline_user.c
@@ -29,7 +29,6 @@
#define _GNU_SOURCE // For asprintf
#include // For PATH_MAX
#include // For asprintf
-#include // For malloc and free
#include "swad_database.h"
#include "swad_global.h"
@@ -292,7 +291,7 @@ void TL_Usr_FormFavSha (Act_Action_t ActionGbl,
Act_GetActCod (ActionUsr),
Gbl.Session.Id,
ParamStr,
- Gbl.Usrs.Other.UsrDat.EncryptedUsrCod) < 0)
+ Gbl.Usrs.Other.UsrDat.EnUsrCod) < 0)
Lay_NotEnoughMemoryExit ();
Frm_StartFormUniqueAnchorOnSubmit (ActUnk,"timeline",OnSubmit);
}
diff --git a/swad_timetable.c b/swad_timetable.c
index d3c5232d..5896e298 100644
--- a/swad_timetable.c
+++ b/swad_timetable.c
@@ -187,10 +187,9 @@ static void TT_TimeTableConfigureIntervalsAndAllocateTimeTable (struct TT_Timeta
for (Weekday = 0;
Weekday < TT_DAYS_PER_WEEK;
Weekday++)
- if ((TT_TimeTable[Weekday] = (struct TT_Cell *)
- malloc (Timetable->Config.IntervalsPerDay *
- sizeof (struct TT_Cell))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for timetable.");
+ if ((TT_TimeTable[Weekday] = malloc (Timetable->Config.IntervalsPerDay *
+ sizeof (*TT_TimeTable[Weekday]))) == NULL)
+ Lay_NotEnoughMemoryExit ();
}
else
{
@@ -1018,7 +1017,7 @@ static void TT_FillTimeTableFromDB (struct TT_Timetable *Timetable,
case TT_TUTORING_TIMETABLE:
Str_Copy (TT_TimeTable[Weekday][Interval].Columns[FirstFreeColumn].Info,
row[3],
- TT_MAX_BYTES_INFO);
+ sizeof (TT_TimeTable[Weekday][Interval].Columns[FirstFreeColumn].Info) - 1);
break;
}
@@ -1136,7 +1135,7 @@ static void TT_ModifTimeTable (struct TT_Timetable *Timetable)
TT_TimeTable[Timetable->Weekday][Timetable->Interval].Columns[Timetable->Column].DurationIntervals = Timetable->DurationIntervals;
Str_Copy (TT_TimeTable[Timetable->Weekday][Timetable->Interval].Columns[Timetable->Column].Info,
Timetable->Info,
- TT_MAX_BYTES_INFO);
+ sizeof (TT_TimeTable[Timetable->Weekday][Timetable->Interval].Columns[Timetable->Column].Info) - 1);
}
}
@@ -1387,9 +1386,9 @@ static unsigned TT_CalculateColsToDrawInCell (const struct TT_Timetable *Timetab
if (TopCall) // Top call, non recursive call
/****** Allocate space to store list of intervals already checked
and initialize to false by using calloc *****/
- if ((TT_IntervalsChecked = (bool *) calloc (Timetable->Config.IntervalsPerDay,
- sizeof (bool))) == NULL)
- Lay_ShowErrorAndExit ("Error allocating memory for timetable.");
+ if ((TT_IntervalsChecked = calloc (Timetable->Config.IntervalsPerDay,
+ sizeof (*TT_IntervalsChecked))) == NULL)
+ Lay_NotEnoughMemoryExit ();
ColumnsToDraw = TT_TimeTable[Weekday][Interval].NumColumns;
diff --git a/swad_user.c b/swad_user.c
index 1bbcabe6..582e3905 100644
--- a/swad_user.c
+++ b/swad_user.c
@@ -304,7 +304,7 @@ void Usr_InformAboutNumClicksBeforePhoto (void)
void Usr_UsrDataConstructor (struct UsrData *UsrDat)
{
/***** Allocate memory for the comments *****/
- if ((UsrDat->Comments = (char *) malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
+ if ((UsrDat->Comments = malloc (Cns_MAX_BYTES_TEXT + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Initialize to zero the data of the user *****/
@@ -320,7 +320,7 @@ void Usr_UsrDataConstructor (struct UsrData *UsrDat)
void Usr_ResetUsrDataExceptUsrCodAndIDs (struct UsrData *UsrDat)
{
- UsrDat->EncryptedUsrCod[0] = '\0';
+ UsrDat->EnUsrCod[0] = '\0';
UsrDat->Nickname[0] = '\0';
UsrDat->Password[0] = '\0';
UsrDat->Roles.InCurrentCrs.Role = Rol_UNK;
@@ -331,7 +331,7 @@ void Usr_ResetUsrDataExceptUsrCodAndIDs (struct UsrData *UsrDat)
UsrDat->Sex = Usr_SEX_UNKNOWN;
UsrDat->Surname1[0] = '\0';
UsrDat->Surname2[0] = '\0';
- UsrDat->FirstName[0] = '\0';
+ UsrDat->FrstName[0] = '\0';
UsrDat->FullName[0] = '\0';
UsrDat->Email[0] = '\0';
@@ -419,7 +419,8 @@ void Usr_GetAllUsrDataFromUsrCod (struct UsrData *UsrDat,Usr_GetPrefs_t GetPrefs
void Usr_AllocateListUsrCods (struct ListUsrCods *ListUsrCods)
{
- if ((ListUsrCods->Lst = (long *) malloc (ListUsrCods->NumUsrs * sizeof (long))) == NULL)
+ if ((ListUsrCods->Lst = malloc (ListUsrCods->NumUsrs *
+ sizeof (*ListUsrCods->Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
}
@@ -458,13 +459,13 @@ void Usr_GetUsrCodFromEncryptedUsrCod (struct UsrData *UsrDat)
MYSQL_ROW row;
unsigned long NumRows;
- if (UsrDat->EncryptedUsrCod[0])
+ if (UsrDat->EnUsrCod[0])
{
/***** Get user's code from database *****/
NumRows = DB_QuerySELECT (&mysql_res,"can not get user's code",
"SELECT UsrCod FROM usr_data"
" WHERE EncryptedUsrCod='%s'",
- UsrDat->EncryptedUsrCod);
+ UsrDat->EnUsrCod);
if (NumRows != 1)
Lay_ShowErrorAndExit ("Error when getting user's code.");
@@ -581,12 +582,10 @@ void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat,Usr_GetPrefs_t GetPrefs)
row = mysql_fetch_row (mysql_res);
/* Get encrypted user's code (row[0]) */
- Str_Copy (UsrDat->EncryptedUsrCod,row[0],
- Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
+ Str_Copy (UsrDat->EnUsrCod,row[0],sizeof (UsrDat->EnUsrCod) - 1);
/* Get encrypted password (row[1]) */
- Str_Copy (UsrDat->Password,row[1],
- Pwd_BYTES_ENCRYPTED_PASSWORD);
+ Str_Copy (UsrDat->Password,row[1],sizeof (UsrDat->Password) - 1);
/* Get roles */
UsrDat->Roles.InCurrentCrs.Role = Rol_GetRoleUsrInCrs (UsrDat->UsrCod,
@@ -596,23 +595,19 @@ void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat,Usr_GetPrefs_t GetPrefs)
Rol_GetRolesInAllCrssIfNotYetGot (UsrDat);
/* Get name (row[2], row[3], row[4]) */
- Str_Copy (UsrDat->Surname1,row[2],
- Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
- Str_Copy (UsrDat->Surname2,row[3],
- Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
- Str_Copy (UsrDat->FirstName,row[4],
- Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
+ Str_Copy (UsrDat->Surname1,row[2],sizeof (UsrDat->Surname1) - 1);
+ Str_Copy (UsrDat->Surname2,row[3],sizeof (UsrDat->Surname2) - 1);
+ Str_Copy (UsrDat->FrstName,row[4],sizeof (UsrDat->FrstName) - 1);
Str_ConvertToTitleType (UsrDat->Surname1 );
Str_ConvertToTitleType (UsrDat->Surname2 );
- Str_ConvertToTitleType (UsrDat->FirstName);
+ Str_ConvertToTitleType (UsrDat->FrstName);
Usr_BuildFullName (UsrDat); // Create full name using FirstName, Surname1 and Surname2
/* Get sex (row[5]) */
UsrDat->Sex = Usr_GetSexFromStr (row[5]);
/* Get photo (row[6]) */
- Str_Copy (UsrDat->Photo,row[6],
- Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
+ Str_Copy (UsrDat->Photo,row[6],sizeof (UsrDat->Photo) - 1);
/* Get photo visibility (row[7]) */
UsrDat->PhotoVisibility = Pri_GetVisibilityFromStr (row[7]);
@@ -635,16 +630,12 @@ void Usr_GetUsrDataFromUsrCod (struct UsrData *UsrDat,Usr_GetPrefs_t GetPrefs)
UsrDat->Tch.CtrCod = Str_ConvertStrCodToLongCod (row[14]);
/* Get office (row[15]) and office phone (row[16]) */
- Str_Copy (UsrDat->Tch.Office,row[15],
- Usr_MAX_BYTES_ADDRESS);
- Str_Copy (UsrDat->Tch.OfficePhone,row[16],
- Usr_MAX_BYTES_PHONE);
+ Str_Copy (UsrDat->Tch.Office ,row[15],sizeof (UsrDat->Tch.Office ) - 1);
+ Str_Copy (UsrDat->Tch.OfficePhone,row[16],sizeof (UsrDat->Tch.OfficePhone) - 1);
/* Get phones (row[17]) and row[18] */
- Str_Copy (UsrDat->Phone[0],row[17],
- Usr_MAX_BYTES_PHONE);
- Str_Copy (UsrDat->Phone[1],row[18],
- Usr_MAX_BYTES_PHONE);
+ Str_Copy (UsrDat->Phone[0],row[17],sizeof (UsrDat->Phone[0]) - 1);
+ Str_Copy (UsrDat->Phone[1],row[18],sizeof (UsrDat->Phone[1]) - 1);
/* Get birthday (row[19]) */
Dat_GetDateFromYYYYMMDD (&(UsrDat->Birthday),row[19]);
@@ -740,8 +731,7 @@ static void Usr_GetUsrCommentsFromString (char *Str,struct UsrData *UsrDat)
/***** Check that memory for comments is allocated *****/
if (UsrDat->Comments)
/***** Copy comments from Str to Comments *****/
- Str_Copy (UsrDat->Comments,Str,
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (UsrDat->Comments,Str,Cns_MAX_BYTES_TEXT - 1);
}
/*****************************************************************************/
@@ -860,21 +850,16 @@ static Usr_Sex_t Usr_GetSexFromStr (const char *Str)
void Usr_BuildFullName (struct UsrData *UsrDat)
{
- Str_Copy (UsrDat->FullName,UsrDat->FirstName,
- Usr_MAX_BYTES_FULL_NAME);
+ Str_Copy (UsrDat->FullName,UsrDat->FrstName,sizeof (UsrDat->FullName) - 1);
if (UsrDat->Surname1[0])
{
- Str_Concat (UsrDat->FullName," ",
- Usr_MAX_BYTES_FULL_NAME);
- Str_Concat (UsrDat->FullName,UsrDat->Surname1,
- Usr_MAX_BYTES_FULL_NAME);
+ Str_Concat (UsrDat->FullName," " ,sizeof (UsrDat->FullName) - 1);
+ Str_Concat (UsrDat->FullName,UsrDat->Surname1,sizeof (UsrDat->FullName) - 1);
}
if (UsrDat->Surname2[0])
{
- Str_Concat (UsrDat->FullName," ",
- Usr_MAX_BYTES_FULL_NAME);
- Str_Concat (UsrDat->FullName,UsrDat->Surname2,
- Usr_MAX_BYTES_FULL_NAME);
+ Str_Concat (UsrDat->FullName," " ,sizeof (UsrDat->FullName) - 1);
+ Str_Concat (UsrDat->FullName,UsrDat->Surname2,sizeof (UsrDat->FullName) - 1);
}
}
@@ -885,7 +870,7 @@ void Usr_BuildFullName (struct UsrData *UsrDat)
void Usr_WriteFirstNameBRSurnames (const struct UsrData *UsrDat)
{
/***** Write first name and surname 1 *****/
- HTM_Txt (UsrDat->FirstName);
+ HTM_Txt (UsrDat->FrstName);
HTM_BR ();
HTM_Txt (UsrDat->Surname1);
@@ -1151,10 +1136,8 @@ unsigned Usr_GetNumUsrsInCrssOfAUsr (long UsrCod,Rol_Role_t UsrRole,
{
sprintf (UnsignedStr,"%u",(unsigned) Role);
if (OthersRolesStr[0]) // Not empty
- Str_Concat (OthersRolesStr,",",
- Usr_MAX_BYTES_ROLES_STR);
- Str_Concat (OthersRolesStr,UnsignedStr,
- Usr_MAX_BYTES_ROLES_STR);
+ Str_Concat (OthersRolesStr,",",sizeof (OthersRolesStr) - 1);
+ Str_Concat (OthersRolesStr,UnsignedStr,sizeof (OthersRolesStr) - 1);
}
NumUsrs =
(unsigned) DB_QueryCOUNT ("can not get number of users",
@@ -2431,8 +2414,7 @@ void Usr_GetMainDeg (long UsrCod,
row = mysql_fetch_row (mysql_res);
/* Get degree name (row[0]) */
- Str_Copy (ShrtName,row[0],
- Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
+ Str_Copy (ShrtName,row[0],Cns_HIERARCHY_MAX_BYTES_SHRT_NAME);
/* Get maximum role (row[1]) */
*MaxRole = Rol_ConvertUnsignedStrToRole (row[1]);
@@ -2598,7 +2580,7 @@ void Usr_WelcomeUsr (void)
{
if (Gbl.Usrs.Me.UsrDat.Prefs.Language == Txt_Current_CGI_SWAD_Language)
{
- if (Gbl.Usrs.Me.UsrDat.FirstName[0])
+ if (Gbl.Usrs.Me.UsrDat.FrstName[0])
{
/***** New year greeting *****/
if (Gbl.Now.Date.Day == 1 &&
@@ -2616,7 +2598,7 @@ void Usr_WelcomeUsr (void)
/* Start alert */
Ale_ShowAlertAndButton1 (Ale_INFO,Txt_Happy_birthday_X,
- Gbl.Usrs.Me.UsrDat.FirstName);
+ Gbl.Usrs.Me.UsrDat.FrstName);
/* Show cake icon */
HTM_IMG (Gbl.Prefs.URLIconSet,"birthday-cake.svg",NULL,
@@ -2690,11 +2672,10 @@ void Usr_CreateBirthdayStrDB (const struct UsrData *UsrDat,
if (UsrDat->Birthday.Year == 0 ||
UsrDat->Birthday.Month == 0 ||
UsrDat->Birthday.Day == 0)
- Str_Copy (BirthdayStrDB,"NULL", // Without apostrophes
- Usr_BIRTHDAY_STR_DB_LENGTH);
+ Str_Copy (BirthdayStrDB,"NULL",Usr_BIRTHDAY_STR_DB_LENGTH); // Without apostrophes
else
snprintf (BirthdayStrDB,Usr_BIRTHDAY_STR_DB_LENGTH + 1,
- "'%04u-%02u-%02u'", // With apostrophes
+ "'%04u-%02u-%02u'", // With apostrophes
UsrDat->Birthday.Year,
UsrDat->Birthday.Month,
UsrDat->Birthday.Day);
@@ -2787,8 +2768,8 @@ void Usr_WriteLoggedUsrHead (void)
"PHOTO18x24",Pho_ZOOM,false);
/***** User's name *****/
- if (Gbl.Usrs.Me.UsrDat.FirstName[0])
- HTM_TxtF (" %s",Gbl.Usrs.Me.UsrDat.FirstName);
+ if (Gbl.Usrs.Me.UsrDat.FrstName[0])
+ HTM_TxtF (" %s",Gbl.Usrs.Me.UsrDat.FrstName);
HTM_DIV_End ();
}
@@ -2888,7 +2869,7 @@ unsigned Usr_GetParamOtherUsrIDNickOrEMailAndGetUsrCods (struct ListUsrCods *Lis
Str_Copy (Gbl.Usrs.Other.UsrDat.IDs.List[0].ID,
Gbl.Usrs.Other.UsrDat.UsrIDNickOrEmail,
- ID_MAX_BYTES_USR_ID);
+ sizeof (Gbl.Usrs.Other.UsrDat.IDs.List[0].ID) - 1);
Str_ConvertToUpperText (Gbl.Usrs.Other.UsrDat.IDs.List[0].ID);
/* Check if user's ID exists in database */
@@ -2934,9 +2915,9 @@ void Usr_PutParamUsrCodEncrypted (const char EncryptedUsrCod[Cry_BYTES_ENCRYPTED
void Usr_GetParamOtherUsrCodEncrypted (struct UsrData *UsrDat)
{
- Par_GetParToText ("OtherUsrCod",UsrDat->EncryptedUsrCod,
+ Par_GetParToText ("OtherUsrCod",UsrDat->EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
- if (UsrDat->EncryptedUsrCod[0]) // If parameter exists...
+ if (UsrDat->EnUsrCod[0]) // If parameter exists...
{
Usr_GetUsrCodFromEncryptedUsrCod (UsrDat);
if (UsrDat->UsrCod < 0) // Check is user's code is valid
@@ -3184,7 +3165,7 @@ static bool Usr_ChkUsrAndGetUsrDataFromDirectLogin (void)
ID_ReallocateListIDs (&Gbl.Usrs.Me.UsrDat,1);
Str_Copy (Gbl.Usrs.Me.UsrDat.IDs.List[0].ID,Gbl.Usrs.Me.UsrIdLogin,
- ID_MAX_BYTES_USR_ID);
+ sizeof (Gbl.Usrs.Me.UsrDat.IDs.List[0].ID) - 1);
Str_ConvertToUpperText (Gbl.Usrs.Me.UsrDat.IDs.List[0].ID);
/* Check if user's ID exists in database, and get user's data */
@@ -3355,19 +3336,15 @@ static void Usr_SetMyPrefsAndRoles (void)
Gbl.Prefs.Menu = Gbl.Usrs.Me.UsrDat.Prefs.Menu;
Gbl.Prefs.SideCols = Gbl.Usrs.Me.UsrDat.Prefs.SideCols;
- Gbl.Prefs.Theme = Gbl.Usrs.Me.UsrDat.Prefs.Theme;
- snprintf (URL,sizeof (URL),
- "%s/%s",
+ Gbl.Prefs.Theme = Gbl.Usrs.Me.UsrDat.Prefs.Theme;
+ snprintf (URL,sizeof (URL),"%s/%s",
Cfg_URL_ICON_THEMES_PUBLIC,The_ThemeId[Gbl.Prefs.Theme]);
- Str_Copy (Gbl.Prefs.URLTheme,URL,
- PATH_MAX);
+ Str_Copy (Gbl.Prefs.URLTheme ,URL,sizeof (Gbl.Prefs.URLTheme ) - 1);
Gbl.Prefs.IconSet = Gbl.Usrs.Me.UsrDat.Prefs.IconSet;
- snprintf (URL,sizeof (URL),
- "%s/%s",
+ snprintf (URL,sizeof (URL),"%s/%s",
Cfg_URL_ICON_SETS_PUBLIC,Ico_IconSetId[Gbl.Prefs.IconSet]);
- Str_Copy (Gbl.Prefs.URLIconSet,URL,
- PATH_MAX);
+ Str_Copy (Gbl.Prefs.URLIconSet,URL,sizeof (Gbl.Prefs.URLIconSet) - 1);
/***** Construct the path to my directory *****/
Usr_ConstructPathUsr (Gbl.Usrs.Me.UsrDat.UsrCod,Gbl.Usrs.Me.PathDir);
@@ -3593,17 +3570,14 @@ void Usr_WriteRowUsrMainData (unsigned NumUsr,struct UsrData *UsrDat,
/***** Checkbox to select user *****/
// Two colors are used alternatively to better distinguish the rows
if (UsrIsTheMsgSender)
- Str_Copy (BgColor,"LIGHT_GREEN",
- Usr_MAX_BYTES_BG_COLOR);
+ Str_Copy (BgColor,"LIGHT_GREEN",sizeof (BgColor) - 1);
else
- snprintf (BgColor,sizeof (BgColor),
- "COLOR%u",
- Gbl.RowEvenOdd);
+ snprintf (BgColor,sizeof (BgColor),"COLOR%u",Gbl.RowEvenOdd);
if (PutCheckBoxToSelectUsr)
{
HTM_TD_Begin ("class=\"CM %s\"",BgColor);
- Usr_PutCheckboxToSelectUser (Role,UsrDat->EncryptedUsrCod,UsrIsTheMsgSender,
+ Usr_PutCheckboxToSelectUser (Role,UsrDat->EnUsrCod,UsrIsTheMsgSender,
SelectedUsrs);
HTM_TD_End ();
}
@@ -3837,8 +3811,7 @@ static void Usr_WriteRowStdAllData (struct UsrData *UsrDat,char *GroupNames)
if (Rec_GetFieldFromCrsRecord (UsrDat->UsrCod,Gbl.Crs.Records.LstFields.Lst[NumField].FieldCod,&mysql_res))
{
row = mysql_fetch_row (mysql_res);
- Str_Copy (Text,row[0],
- Cns_MAX_BYTES_TEXT);
+ Str_Copy (Text,row[0],sizeof (Text) - 1);
Str_ChangeFormat (Str_FROM_HTML,Str_TO_RIGOROUS_HTML,
Text,Cns_MAX_BYTES_TEXT,false); // Se convierte of HTML a HTML respetuoso
}
@@ -4003,7 +3976,7 @@ static void Usr_WriteMainUsrDataExceptUsrID (struct UsrData *UsrDat,
" ",
NULL,true,UsrDat->Accepted);
Usr_WriteUsrData (BgColor,
- UsrDat->FirstName[0] ? UsrDat->FirstName :
+ UsrDat->FrstName[0] ? UsrDat->FrstName :
" ",
NULL,true,UsrDat->Accepted);
}
@@ -4021,9 +3994,7 @@ static void Usr_WriteEmail (struct UsrData *UsrDat,const char *BgColor)
{
ShowEmail = Mai_ICanSeeOtherUsrEmail (UsrDat);
if (ShowEmail)
- snprintf (MailLink,sizeof (MailLink),
- "mailto:%s",
- UsrDat->Email);
+ snprintf (MailLink,sizeof (MailLink),"mailto:%s",UsrDat->Email);
}
else
ShowEmail = false;
@@ -4460,7 +4431,7 @@ static void Usr_BuildQueryToGetUsrsLstCrs (char **Query,Rol_Role_t Role)
}
/***** Allocate space for query *****/
- if ((*Query = (char *) malloc (Usr_MAX_BYTES_QUERY_GET_LIST_USRS + 1)) == NULL)
+ if ((*Query = malloc (Usr_MAX_BYTES_QUERY_GET_LIST_USRS + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Create query for users in the course *****/
@@ -4491,7 +4462,8 @@ static void Usr_BuildQueryToGetUsrsLstCrs (char **Query,Rol_Role_t Role)
Grp_GetListGrpTypesInThisCrs (Grp_ONLY_GROUP_TYPES_WITH_GROUPS);
/***** Allocate memory for list of booleans AddStdsWithoutGroupOf *****/
- if ((AddStdsWithoutGroupOf = (bool *) calloc (Gbl.Crs.Grps.GrpTypes.Num,sizeof (bool))) == NULL)
+ if ((AddStdsWithoutGroupOf = calloc (Gbl.Crs.Grps.GrpTypes.Num,
+ sizeof (*AddStdsWithoutGroupOf))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Initialize vector of booleans that indicates whether it's necessary add to the list
@@ -4534,17 +4506,12 @@ static void Usr_BuildQueryToGetUsrsLstCrs (char **Query,Rol_Role_t Role)
Str_Concat (*Query,NumPositiveCods ? " OR GrpCod='" :
" GrpCod='",
Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
- snprintf (LongStr,sizeof (LongStr),
- "%ld",
- GrpCod);
- Str_Concat (*Query,LongStr,
- Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
- Str_Concat (*Query,"'",
- Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
+ snprintf (LongStr,sizeof (LongStr),"%ld",GrpCod);
+ Str_Concat (*Query,LongStr,Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
+ Str_Concat (*Query,"'",Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
NumPositiveCods++;
}
- Str_Concat (*Query,")",
- Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
+ Str_Concat (*Query,")",Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
}
}
@@ -4555,30 +4522,25 @@ static void Usr_BuildQueryToGetUsrsLstCrs (char **Query,Rol_Role_t Role)
if (AddStdsWithoutGroupOf[NumGrpTyp])
{
if (NumPositiveCods || NumNegativeCods)
- Str_Concat (*Query," OR ",
- Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
+ Str_Concat (*Query," OR ",Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
else
- Str_Concat (*Query," AND (",
- Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
+ Str_Concat (*Query," AND (",Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
/* Select all the students of the course who don't belong to any group of type GrpTypCod */
Str_Concat (*Query,"crs_usr.UsrCod NOT IN"
" (SELECT DISTINCT crs_grp_usr.UsrCod"
" FROM crs_grp,crs_grp_usr"
" WHERE crs_grp.GrpTypCod='",
Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
- snprintf (LongStr,sizeof (LongStr),
- "%ld",
+ snprintf (LongStr,sizeof (LongStr),"%ld",
Gbl.Crs.Grps.GrpTypes.LstGrpTypes[NumGrpTyp].GrpTypCod);
- Str_Concat (*Query,LongStr,
- Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
+ Str_Concat (*Query,LongStr,Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
Str_Concat (*Query,"' AND crs_grp.GrpCod=crs_grp_usr.GrpCod)",
Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
NumNegativeCods++;
}
if (NumPositiveCods ||
NumNegativeCods)
- Str_Concat (*Query,")",
- Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
+ Str_Concat (*Query,")",Usr_MAX_BYTES_QUERY_GET_LIST_USRS);
/***** Free memory used by the list of booleans AddStdsWithoutGroupOf *****/
free (AddStdsWithoutGroupOf);
@@ -5411,32 +5373,19 @@ static void Usr_GetListUsrsFromQuery (char *Query,Rol_Role_t Role,Hie_Lvl_Level_
/* Get user's code (row[0]) */
UsrInList->UsrCod = Str_ConvertStrCodToLongCod (row[0]);
- /* Get encrypted user's code (row[1]) */
- Str_Copy (UsrInList->EncryptedUsrCod,row[1],
- Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
-
- /* Get encrypted password (row[2]) */
- Str_Copy (UsrInList->Password,row[2],
- Pwd_BYTES_ENCRYPTED_PASSWORD);
-
- /* Get user's surname 1 (row[3]) */
- Str_Copy (UsrInList->Surname1,row[3],
- Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
-
- /* Get user's surname 2 (row[4]) */
- Str_Copy (UsrInList->Surname2,row[4],
- Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
-
- /* Get user's first name (row[5]) */
- Str_Copy (UsrInList->FirstName,row[5],
- Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
+ /* Get encrypted user's code (row[1]), encrypted password (row[2]),
+ surname 1 (row[3]), surname 2 (row[4]), first name (row[5]), */
+ Str_Copy (UsrInList->EnUsrCod,row[1],sizeof (UsrInList->EnUsrCod) - 1);
+ Str_Copy (UsrInList->Password ,row[2],sizeof (UsrInList->Password ) - 1);
+ Str_Copy (UsrInList->Surname1 ,row[3],sizeof (UsrInList->Surname1 ) - 1);
+ Str_Copy (UsrInList->Surname2 ,row[4],sizeof (UsrInList->Surname2 ) - 1);
+ Str_Copy (UsrInList->FrstName ,row[5],sizeof (UsrInList->FrstName ) - 1);
/* Get user's sex (row[6]) */
UsrInList->Sex = Usr_GetSexFromStr (row[6]);
/* Get user's photo (row[7]) */
- Str_Copy (UsrInList->Photo,row[7],
- Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
+ Str_Copy (UsrInList->Photo ,row[7],sizeof (UsrInList->Photo ) - 1);
/* Get user's photo visibility (row[8]) */
UsrInList->PhotoVisibility = Pri_GetVisibilityFromStr (row[8]);
@@ -5535,18 +5484,13 @@ static void Usr_GetListUsrsFromQuery (char *Query,Rol_Role_t Role,Hie_Lvl_Level_
void Usr_CopyBasicUsrDataFromList (struct UsrData *UsrDat,const struct UsrInList *UsrInList)
{
- UsrDat->UsrCod = UsrInList->UsrCod;
- Str_Copy (UsrDat->EncryptedUsrCod,UsrInList->EncryptedUsrCod,
- Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
- Str_Copy (UsrDat->Surname1,UsrInList->Surname1,
- Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
- Str_Copy (UsrDat->Surname2,UsrInList->Surname2,
- Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
- Str_Copy (UsrDat->FirstName,UsrInList->FirstName,
- Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME);
- UsrDat->Sex = UsrInList->Sex;
- Str_Copy (UsrDat->Photo,UsrInList->Photo,
- Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
+ UsrDat->UsrCod = UsrInList->UsrCod;
+ Str_Copy (UsrDat->EnUsrCod,UsrInList->EnUsrCod,sizeof (UsrDat->EnUsrCod) - 1);
+ Str_Copy (UsrDat->Surname1,UsrInList->Surname1,sizeof (UsrDat->Surname1) - 1);
+ Str_Copy (UsrDat->Surname2,UsrInList->Surname2,sizeof (UsrDat->Surname2) - 1);
+ Str_Copy (UsrDat->FrstName,UsrInList->FrstName,sizeof (UsrDat->FrstName) - 1);
+ UsrDat->Sex = UsrInList->Sex;
+ Str_Copy (UsrDat->Photo ,UsrInList->Photo ,sizeof (UsrDat->Photo ) - 1);
UsrDat->PhotoVisibility = UsrInList->PhotoVisibility;
UsrDat->CtyCod = UsrInList->CtyCod;
UsrDat->InsCod = UsrInList->InsCod;
@@ -5570,7 +5514,8 @@ if (Gbl.Usrs.Me.Roles.LoggedRole == Rol_SYS_ADM)
}
*/
if (Gbl.Usrs.LstUsrs[Role].NumUsrs)
- if ((Gbl.Usrs.LstUsrs[Role].Lst = (struct UsrInList *) calloc (Gbl.Usrs.LstUsrs[Role].NumUsrs,sizeof (struct UsrInList))) == NULL)
+ if ((Gbl.Usrs.LstUsrs[Role].Lst = calloc (Gbl.Usrs.LstUsrs[Role].NumUsrs,
+ sizeof (*Gbl.Usrs.LstUsrs[Role].Lst))) == NULL)
Lay_NotEnoughMemoryExit ();
}
@@ -5659,9 +5604,9 @@ void Usr_CreateListSelectedUsrsCodsAndFillWithOtherUsr (struct SelectedUsrs *Sel
if (!SelectedUsrs->List[Rol_UNK])
{
if ((SelectedUsrs->List[Rol_UNK] =
- (char *) malloc (Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1)) == NULL)
+ malloc (Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
- Str_Copy (SelectedUsrs->List[Rol_UNK],Gbl.Usrs.Other.UsrDat.EncryptedUsrCod,
+ Str_Copy (SelectedUsrs->List[Rol_UNK],Gbl.Usrs.Other.UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
SelectedUsrs->Filled = true;
}
@@ -5882,7 +5827,7 @@ bool Usr_GetListMsgRecipientsWrittenExplicitelyBySender (bool WriteErrorMsgs)
ID_ReallocateListIDs (&UsrDat,1);
Str_Copy (UsrDat.IDs.List[0].ID,UsrIDNickOrEmail,
- ID_MAX_BYTES_USR_ID);
+ sizeof (UsrDat.IDs.List[0].ID) - 1);
/***** Check if a user exists having this user's ID *****/
if (ID_GetListUsrCodsFromUsrID (&UsrDat,NULL,&ListUsrCods,false))
@@ -5918,9 +5863,9 @@ bool Usr_GetListMsgRecipientsWrittenExplicitelyBySender (bool WriteErrorMsgs)
Usr_GetUsrDataFromUsrCod (&UsrDat,Usr_DONT_GET_PREFS); // Really only EncryptedUsrCod is needed
/* Find if encrypted user's code is already in list */
- if (!Usr_FindEncryptedUsrCodsInListOfSelectedEncryptedUsrCods (UsrDat.EncryptedUsrCod,&Gbl.Usrs.Selected)) // If not in list ==> add it
+ if (!Usr_FindEncryptedUsrCodsInListOfSelectedEncryptedUsrCods (UsrDat.EnUsrCod,&Gbl.Usrs.Selected)) // If not in list ==> add it
{
- LengthUsrCod = strlen (UsrDat.EncryptedUsrCod);
+ LengthUsrCod = strlen (UsrDat.EnUsrCod);
/* Add encrypted user's code to list of users */
if (LengthSelectedUsrsCods == 0) // First user in list
@@ -5929,7 +5874,7 @@ bool Usr_GetListMsgRecipientsWrittenExplicitelyBySender (bool WriteErrorMsgs)
{
/* Add user */
Str_Copy (Gbl.Usrs.Selected.List[Rol_UNK],
- UsrDat.EncryptedUsrCod,
+ UsrDat.EnUsrCod,
Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS);
LengthSelectedUsrsCods = LengthUsrCod;
}
@@ -5945,7 +5890,7 @@ bool Usr_GetListMsgRecipientsWrittenExplicitelyBySender (bool WriteErrorMsgs)
/* Add user */
Str_Copy (Gbl.Usrs.Selected.List[Rol_UNK] + LengthSelectedUsrsCods,
- UsrDat.EncryptedUsrCod,
+ UsrDat.EnUsrCod,
Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS);
LengthSelectedUsrsCods += LengthUsrCod;
}
@@ -6002,7 +5947,7 @@ bool Usr_CheckIfThereAreUsrsInListOfSelectedEncryptedUsrCods (struct SelectedUsr
Ptr = SelectedUsrs->List[Rol_UNK];
while (*Ptr)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
if (UsrDat.UsrCod > 0)
@@ -6025,7 +5970,7 @@ unsigned Usr_CountNumUsrsInListOfSelectedEncryptedUsrCods (struct SelectedUsrs *
Ptr = SelectedUsrs->List[Rol_UNK];
while (*Ptr)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
if (UsrDat.UsrCod > 0)
@@ -6045,7 +5990,7 @@ static void Usr_AllocateListSelectedEncryptedUsrCods (struct SelectedUsrs *Selec
if (!SelectedUsrs->List[Role])
{
if ((SelectedUsrs->List[Role] =
- (char *) malloc (Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS + 1)) == NULL)
+ malloc (Usr_MAX_BYTES_LIST_ENCRYPTED_USR_CODS + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
SelectedUsrs->List[Role][0] = '\0';
}
@@ -6092,7 +6037,8 @@ void Usr_GetListSelectedUsrCods (struct SelectedUsrs *SelectedUsrs,
struct UsrData UsrDat;
/***** Create list of user codes *****/
- if ((*LstSelectedUsrCods = (long *) calloc ((size_t) NumUsrsInList,sizeof (long))) == NULL)
+ if ((*LstSelectedUsrCods = calloc (NumUsrsInList,
+ sizeof (**LstSelectedUsrCods))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Initialize structure with user's data *****/
@@ -6103,7 +6049,7 @@ void Usr_GetListSelectedUsrCods (struct SelectedUsrs *SelectedUsrs,
NumUsr < NumUsrsInList && *Ptr;
NumUsr++)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
(*LstSelectedUsrCods)[NumUsr] = UsrDat.UsrCod;
@@ -6134,7 +6080,7 @@ void Usr_CreateSubqueryUsrCods (long LstSelectedUsrCods[],
/***** Allocate space for subquery *****/
MaxLength = NumUsrsInList * (1 + Cns_MAX_DECIMAL_DIGITS_LONG);
- if ((*SubQueryUsrs = (char *) malloc (MaxLength + 1)) == NULL)
+ if ((*SubQueryUsrs = malloc (MaxLength + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
(*SubQueryUsrs)[0] = '\0';
@@ -6144,15 +6090,12 @@ void Usr_CreateSubqueryUsrCods (long LstSelectedUsrCods[],
NumUsr++)
if (NumUsr)
{
- snprintf (SubQueryOneUsr,sizeof (SubQueryOneUsr),
- ",%ld",
+ snprintf (SubQueryOneUsr,sizeof (SubQueryOneUsr),",%ld",
LstSelectedUsrCods[NumUsr]);
- Str_Concat (*SubQueryUsrs,SubQueryOneUsr,
- MaxLength);
+ Str_Concat (*SubQueryUsrs,SubQueryOneUsr,MaxLength);
}
else
- snprintf (*SubQueryUsrs,sizeof (SubQueryOneUsr),
- "%ld",
+ snprintf (*SubQueryUsrs,sizeof (SubQueryOneUsr),"%ld",
LstSelectedUsrCods[NumUsr]);
}
@@ -6169,7 +6112,7 @@ static void Usr_AllocateListOtherRecipients (void)
{
if (!Gbl.Usrs.ListOtherRecipients)
{
- if ((Gbl.Usrs.ListOtherRecipients = (char *) malloc (Nck_MAX_BYTES_LIST_NICKS + 1)) == NULL)
+ if ((Gbl.Usrs.ListOtherRecipients = malloc (Nck_MAX_BYTES_LIST_NICKS + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
Gbl.Usrs.ListOtherRecipients[0] = '\0';
}
@@ -6702,8 +6645,8 @@ static void Usr_ListMainDataStds (bool PutCheckBoxToSelectUsr)
if (Gbl.Usrs.LstUsrs[Rol_STD].NumUsrs)
{
/***** Allocate memory for the string with the list of group names where student belongs to *****/
- if ((GroupNames = (char *) malloc ((Grp_MAX_BYTES_GROUP_NAME + 3) *
- Gbl.Crs.Grps.GrpTypes.NumGrpsTotal)) == NULL)
+ if ((GroupNames = malloc (Gbl.Crs.Grps.GrpTypes.NumGrpsTotal *
+ (Grp_MAX_BYTES_GROUP_NAME + 3))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Begin table with list of students *****/
@@ -7013,7 +6956,7 @@ void Usr_ListAllDataStds (void)
if (Gbl.Scope.Current == Hie_Lvl_CRS)
{
Length = (Grp_MAX_BYTES_GROUP_NAME + 2) * Gbl.Crs.Grps.GrpTypes.NumGrpsTotal;
- if ((GroupNames = (char *) malloc (Length + 1)) == NULL)
+ if ((GroupNames = malloc (Length + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
}
@@ -9096,7 +9039,7 @@ static void Usr_DrawClassPhoto (Usr_ClassPhotoType_t ClassPhotoType,
/***** Checkbox to select this user *****/
if (PutCheckBoxToSelectUsr)
- Usr_PutCheckboxToSelectUser (Role,UsrDat.EncryptedUsrCod,UsrIsTheMsgSender,
+ Usr_PutCheckboxToSelectUser (Role,UsrDat.EnUsrCod,UsrIsTheMsgSender,
SelectedUsrs);
/***** Show photo *****/
@@ -9109,8 +9052,8 @@ static void Usr_DrawClassPhoto (Usr_ClassPhotoType_t ClassPhotoType,
HTM_DIV_Begin ("class=\"CLASSPHOTO_CAPTION\"");
/* Name */
- if (UsrDat.FirstName[0])
- HTM_Txt (UsrDat.FirstName);
+ if (UsrDat.FrstName[0])
+ HTM_Txt (UsrDat.FrstName);
else
HTM_NBSP ();
HTM_BR ();
@@ -9184,14 +9127,12 @@ void Usr_ConstructPathUsr (long UsrCod,char PathUsr[PATH_MAX + 1 + Cns_MAX_DECIM
Fil_CreateDirIfNotExists (Cfg_PATH_USR_PRIVATE);
/***** Path above user's ID *****/
- snprintf (PathAboveUsr,sizeof (PathAboveUsr),
- "%s/%02u",
+ snprintf (PathAboveUsr,sizeof (PathAboveUsr),"%s/%02u",
Cfg_PATH_USR_PRIVATE,(unsigned) (UsrCod % 100));
Fil_CreateDirIfNotExists (PathAboveUsr);
/***** Path for user *****/
- snprintf (PathUsr,PATH_MAX + 1 + Cns_MAX_DECIMAL_DIGITS_LONG + 1,
- "%s/%ld",
+ snprintf (PathUsr,PATH_MAX + 1 + Cns_MAX_DECIMAL_DIGITS_LONG + 1,"%s/%ld",
PathAboveUsr,UsrCod);
}
@@ -9319,22 +9260,20 @@ unsigned Usr_GetNumUsrsInCrss (Hie_Lvl_Level_t Scope,long Cod,unsigned Roles)
/***** Build subquery for roles *****/
if (MoreThanOneRole)
{
- Str_Copy (SubQueryRoles," IN (",Usr_MAX_BYTES_SUBQUERY_ROLES);
+ Str_Copy (SubQueryRoles," IN (",sizeof (SubQueryRoles) - 1);
for (Role = Rol_STD, FirstRole = true;
Role <= Rol_TCH;
Role++)
if (Roles & (1 << Role))
{
- snprintf (UnsignedStr,sizeof (UnsignedStr),
- "%u",
- (unsigned) Role);
+ snprintf (UnsignedStr,sizeof (UnsignedStr),"%u",(unsigned) Role);
if (FirstRole) // Not the first role
FirstRole = false;
else
- Str_Concat (SubQueryRoles,",",Usr_MAX_BYTES_SUBQUERY_ROLES);
- Str_Concat (SubQueryRoles,UnsignedStr,Usr_MAX_BYTES_SUBQUERY_ROLES);
+ Str_Concat (SubQueryRoles,",",sizeof (SubQueryRoles) - 1);
+ Str_Concat (SubQueryRoles,UnsignedStr,sizeof (SubQueryRoles) - 1);
}
- Str_Concat (SubQueryRoles,")",Usr_MAX_BYTES_SUBQUERY_ROLES);
+ Str_Concat (SubQueryRoles,")",sizeof (SubQueryRoles) - 1);
}
else // Only one role
sprintf (SubQueryRoles,"=%u",FirstRoleRequested);
@@ -9904,7 +9843,7 @@ void Usr_RemoveUsrFromUsrBanned (long UsrCod)
void Usr_PrintUsrQRCode (void)
{
- char NewNicknameWithArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
+ char NewNickWithArroba[Nck_MAX_BYTES_NICKNAME_FROM_FORM + 1];
if (Usr_GetParamOtherUsrCodEncryptedAndGetUsrData ())
{
@@ -9916,10 +9855,9 @@ void Usr_PrintUsrQRCode (void)
/***** Show QR code *****/
if (Gbl.Usrs.Other.UsrDat.Nickname[0])
{
- snprintf (NewNicknameWithArroba,sizeof (NewNicknameWithArroba),
- "@%s",
+ snprintf (NewNickWithArroba,sizeof (NewNickWithArroba),"@%s",
Gbl.Usrs.Other.UsrDat.Nickname);
- QR_ImageQRCode (NewNicknameWithArroba);
+ QR_ImageQRCode (NewNickWithArroba);
}
/***** End box *****/
@@ -10014,7 +9952,7 @@ void Usr_ShowTableCellWithUsrData (struct UsrData *UsrDat,unsigned NumRows)
{
/* Begin form to go to user's record card */
Frm_StartForm (NextAction);
- Usr_PutParamUsrCodEncrypted (UsrDat->EncryptedUsrCod);
+ Usr_PutParamUsrCodEncrypted (UsrDat->EnUsrCod);
HTM_BUTTON_SUBMIT_Begin (UsrDat->FullName,"BT_LINK LT AUTHOR_TXT",NULL);
}
@@ -10026,11 +9964,11 @@ void Usr_ShowTableCellWithUsrData (struct UsrData *UsrDat,unsigned NumRows)
HTM_Txt (UsrDat->Surname1);
if (UsrDat->Surname2[0])
HTM_TxtF (" %s",UsrDat->Surname2);
- if (UsrDat->FirstName[0])
+ if (UsrDat->FrstName[0])
{
HTM_Comma ();
HTM_BR ();
- HTM_Txt (UsrDat->FirstName);
+ HTM_Txt (UsrDat->FrstName);
}
if (NextAction == ActUnk)
diff --git a/swad_user.h b/swad_user.h
index 5d7b4564..89213b7f 100644
--- a/swad_user.h
+++ b/swad_user.h
@@ -158,7 +158,7 @@ typedef enum
struct UsrData
{
long UsrCod;
- char EncryptedUsrCod [Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1];
+ char EnUsrCod [Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1];
char UsrIDNickOrEmail[Cns_MAX_BYTES_EMAIL_ADDRESS + 1]; // String to store the ID, nickname or email
struct
{
@@ -182,7 +182,7 @@ struct UsrData
bool Accepted; // User has accepted joining to current course?
char Surname1 [Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1];
char Surname2 [Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1];
- char FirstName [Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1];
+ char FrstName [Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1];
char FullName [Usr_MAX_BYTES_FULL_NAME + 1];
Usr_Sex_t Sex;
char Email [Cns_MAX_BYTES_EMAIL_ADDRESS + 1];
@@ -240,11 +240,11 @@ struct UsrLast
struct UsrInList
{
long UsrCod;
- char EncryptedUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1];
+ char EnUsrCod[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1];
char Password[Pwd_BYTES_ENCRYPTED_PASSWORD + 1];
char Surname1 [Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1];
char Surname2 [Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1];
- char FirstName[Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1];
+ char FrstName[Usr_MAX_BYTES_FIRSTNAME_OR_SURNAME + 1];
Usr_Sex_t Sex;
char Photo[Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64 + 1]; // Name of public link to photo
Pri_Visibility_t PhotoVisibility; // Who can see user's photo
diff --git a/swad_xml.c b/swad_xml.c
index 39bd2804..15300d5c 100644
--- a/swad_xml.c
+++ b/swad_xml.c
@@ -100,7 +100,7 @@ void XML_WriteEndFile (FILE *FileTgt,const char *Type)
void XML_GetTree (const char *XMLBuffer,struct XMLElement **XMLRootElem)
{
/***** Allocate space for the root element *****/
- if ((*XMLRootElem = calloc (1,sizeof (struct XMLElement))) == NULL)
+ if ((*XMLRootElem = calloc (1,sizeof (**XMLRootElem))) == NULL)
Lay_NotEnoughMemoryExit ();
Gbl.XMLPtr = XMLBuffer;
@@ -184,7 +184,7 @@ static void XML_GetElement (struct XMLElement *ParentElem)
/* Copy content */
if (ContentLength)
{
- if ((ParentElem->Content = (char *) malloc (ContentLength + 1)) == NULL)
+ if ((ParentElem->Content = malloc (ContentLength + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
strncpy (ParentElem->Content,StartContent,ContentLength);
ParentElem->Content[ContentLength] = '\0';
@@ -209,7 +209,7 @@ static void XML_GetElement (struct XMLElement *ParentElem)
Gbl.XMLPtr
*/
/***** Allocate space for the child element *****/
- if ((ChildElem = calloc (1,sizeof (struct XMLElement))) == NULL)
+ if ((ChildElem = calloc (1,sizeof (*ChildElem))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Adjust XML elements pointers *****/
@@ -221,7 +221,7 @@ static void XML_GetElement (struct XMLElement *ParentElem)
/***** Get child tag name *****/
ChildElem->TagNameLength = strcspn (Gbl.XMLPtr,">/ \t");
- if ((ChildElem->TagName = (char *) malloc (ChildElem->TagNameLength + 1)) == NULL)
+ if ((ChildElem->TagName = malloc (ChildElem->TagNameLength + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
strncpy (ChildElem->TagName,Gbl.XMLPtr,ChildElem->TagNameLength);
ChildElem->TagName[ChildElem->TagNameLength] = '\0';
@@ -330,7 +330,7 @@ static void XML_GetAttributes (struct XMLElement *Elem)
Gbl.XMLPtr
*/
/***** Allocate space for the attribute *****/
- if ((Attribute = calloc (1,sizeof (struct XMLAttribute))) == NULL)
+ if ((Attribute = calloc (1,sizeof (*Attribute))) == NULL)
Lay_NotEnoughMemoryExit ();
/***** Adjust XML element and attribute pointers *****/
@@ -342,7 +342,7 @@ static void XML_GetAttributes (struct XMLElement *Elem)
/***** Get attribute name *****/
Attribute->AttributeNameLength = strcspn (Gbl.XMLPtr,"=");
- if ((Attribute->AttributeName = (char *) malloc (Attribute->AttributeNameLength + 1)) == NULL)
+ if ((Attribute->AttributeName = malloc (Attribute->AttributeNameLength + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
strncpy (Attribute->AttributeName,Gbl.XMLPtr,Attribute->AttributeNameLength);
Attribute->AttributeName[Attribute->AttributeNameLength] = '\0';
@@ -374,7 +374,7 @@ static void XML_GetAttributes (struct XMLElement *Elem)
Lay_ShowErrorAndExit (ErrorTxt);
}
- if ((Attribute->Content = (char *) malloc (Attribute->ContentLength + 1)) == NULL)
+ if ((Attribute->Content = malloc (Attribute->ContentLength + 1)) == NULL)
Lay_NotEnoughMemoryExit ();
strncpy (Attribute->Content,Gbl.XMLPtr,Attribute->ContentLength);
Attribute->Content[Attribute->ContentLength] = '\0';
diff --git a/swad_zip.c b/swad_zip.c
index d33faadc..5608744e 100644
--- a/swad_zip.c
+++ b/swad_zip.c
@@ -152,7 +152,7 @@ void ZIP_CreateZIPAsgWrk (void)
Ptr = Gbl.Usrs.Selected.List[Rol_UNK];
while (*Ptr)
{
- Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EncryptedUsrCod,
+ Par_GetNextStrUntilSeparParamMult (&Ptr,UsrDat.EnUsrCod,
Cry_BYTES_ENCRYPTED_STR_SHA256_BASE64);
Usr_GetUsrCodFromEncryptedUsrCod (&UsrDat);
@@ -170,10 +170,8 @@ void ZIP_CreateZIPAsgWrk (void)
Brw_CreateDirDownloadTmp ();
/***** Relative path of the directory with the works to compress *****/
- snprintf (Path,sizeof (Path),
- "%s/%s",
- Cfg_PATH_ZIP_PRIVATE,
- Gbl.FileBrowser.ZIP.TmpDir);
+ snprintf (Path,sizeof (Path),"%s/%s",
+ Cfg_PATH_ZIP_PRIVATE,Gbl.FileBrowser.ZIP.TmpDir);
/***** Change to directory of the assignments and works
in order to start the path in the zip file from there *****/
@@ -181,17 +179,13 @@ void ZIP_CreateZIPAsgWrk (void)
Lay_ShowErrorAndExit ("Can not change to temporary folder for compression.");
/***** Create public zip file with the assignment and works *****/
- snprintf (FileNameZIP,sizeof (FileNameZIP),
- "%s.zip",
- Txt_works_ZIP_FILE_NAME);
- snprintf (PathFileZIP,sizeof (PathFileZIP),
- "%s/%s/%s/%s",
+ snprintf (FileNameZIP,sizeof (FileNameZIP),"%s.zip",Txt_works_ZIP_FILE_NAME);
+ snprintf (PathFileZIP,sizeof (PathFileZIP),"%s/%s/%s/%s",
Cfg_PATH_FILE_BROWSER_TMP_PUBLIC,
Gbl.FileBrowser.TmpPubDir.L,
Gbl.FileBrowser.TmpPubDir.R,
FileNameZIP);
- snprintf (StrZip,sizeof (StrZip),
- "nice -n 19 zip -q -r '%s' *",
+ snprintf (StrZip,sizeof (StrZip),"nice -n 19 zip -q -r '%s' *",
PathFileZIP);
Result = system (StrZip);
@@ -208,8 +202,7 @@ void ZIP_CreateZIPAsgWrk (void)
else
{
/***** Create URL pointing to ZIP file *****/
- snprintf (URLWithSpaces,sizeof (URLWithSpaces),
- "%s/%s/%s/%s",
+ snprintf (URLWithSpaces,sizeof (URLWithSpaces),"%s/%s/%s/%s",
Cfg_URL_FILE_BROWSER_TMP_PUBLIC,
Gbl.FileBrowser.TmpPubDir.L,
Gbl.FileBrowser.TmpPubDir.R,
@@ -240,9 +233,8 @@ static void ZIP_CreateTmpDirForCompression (void)
/***** Create a new temporary directory *****/
Str_Copy (Gbl.FileBrowser.ZIP.TmpDir,Gbl.UniqueNameEncrypted,
- NAME_MAX);
- snprintf (PathDirTmp,sizeof (PathDirTmp),
- "%s/%s",
+ sizeof (Gbl.FileBrowser.ZIP.TmpDir) - 1);
+ snprintf (PathDirTmp,sizeof (PathDirTmp),"%s/%s",
Cfg_PATH_ZIP_PRIVATE,Gbl.FileBrowser.ZIP.TmpDir);
if (mkdir (PathDirTmp,(mode_t) 0xFFF))
Lay_ShowErrorAndExit ("Can not create temporary folder for compression.");
@@ -266,43 +258,32 @@ static void ZIP_CreateDirCompressionUsr (struct UsrData *UsrDat)
with a name that identifies the owner
of the assignments and works *****/
/* Create link name for this user */
- Str_Copy (FullNameAndUsrID,UsrDat->Surname1,
- NAME_MAX);
+ Str_Copy (FullNameAndUsrID,UsrDat->Surname1,sizeof (FullNameAndUsrID) - 1);
if (UsrDat->Surname1[0] &&
UsrDat->Surname2[0])
- Str_Concat (FullNameAndUsrID,"_", // Separation between surname 1 and surname 2
- NAME_MAX);
- Str_Concat (FullNameAndUsrID,UsrDat->Surname2,
- NAME_MAX);
+ Str_Concat (FullNameAndUsrID,"_",sizeof (FullNameAndUsrID) - 1); // Separation between surname 1 and surname 2
+ Str_Concat (FullNameAndUsrID,UsrDat->Surname2,sizeof (FullNameAndUsrID) - 1);
if ((UsrDat->Surname1[0] ||
UsrDat->Surname2[0]) &&
- UsrDat->FirstName[0])
- Str_Concat (FullNameAndUsrID,"_", // Separation between surnames and first name
- NAME_MAX);
- Str_Concat (FullNameAndUsrID,UsrDat->FirstName,
- NAME_MAX);
+ UsrDat->FrstName[0])
+ Str_Concat (FullNameAndUsrID,"_",sizeof (FullNameAndUsrID) - 1); // Separation between surnames and first name
+ Str_Concat (FullNameAndUsrID,UsrDat->FrstName,sizeof (FullNameAndUsrID) - 1);
if ((UsrDat->Surname1[0] ||
UsrDat->Surname2[0] ||
- UsrDat->FirstName[0]) &&
+ UsrDat->FrstName[0]) &&
UsrDat->IDs.Num)
- Str_Concat (FullNameAndUsrID,"-", // Separation between name and ID
- NAME_MAX);
+ Str_Concat (FullNameAndUsrID,"-",sizeof (FullNameAndUsrID) - 1); // Separation between name and ID
if (UsrDat->IDs.Num) // If this user has at least one ID
Str_Concat (FullNameAndUsrID,UsrDat->IDs.List[0].ID,
- NAME_MAX); // First user's ID
+ sizeof (FullNameAndUsrID) - 1); // First user's ID
Str_ConvertToValidFileName (FullNameAndUsrID);
/* Create path to folder and link */
snprintf (PathFolderUsrInsideCrs,sizeof (PathFolderUsrInsideCrs),
"%s/usr/%02u/%ld",
- Gbl.Crs.PathPriv,
- (unsigned) (UsrDat->UsrCod % 100),
- UsrDat->UsrCod);
- snprintf (LinkTmpUsr,sizeof (LinkTmpUsr),
- "%s/%s/%s",
- Cfg_PATH_ZIP_PRIVATE,
- Gbl.FileBrowser.ZIP.TmpDir,
- FullNameAndUsrID);
+ Gbl.Crs.PathPriv,(unsigned) (UsrDat->UsrCod % 100),UsrDat->UsrCod);
+ snprintf (LinkTmpUsr,sizeof (LinkTmpUsr),"%s/%s/%s",
+ Cfg_PATH_ZIP_PRIVATE,Gbl.FileBrowser.ZIP.TmpDir,FullNameAndUsrID);
/* Try to create a link named LinkTmpUsr to PathFolderUsrInsideCrs */
if (symlink (PathFolderUsrInsideCrs,LinkTmpUsr) != 0)
@@ -313,9 +294,7 @@ static void ZIP_CreateDirCompressionUsr (struct UsrData *UsrDat)
{
// Link exists ==> a former user share the same name and ID
// (probably a unique user has created two or more accounts)
- snprintf (Link,sizeof (Link),
- "%s-%u",
- LinkTmpUsr,NumTry);
+ snprintf (Link,sizeof (Link),"%s-%u",LinkTmpUsr,NumTry);
if (symlink (PathFolderUsrInsideCrs,Link) == 0)
Success = true;
}
@@ -374,12 +353,10 @@ static void ZIP_CompressFolderIntoZIP (void)
Brw_CreateDirDownloadTmp ();
/***** Create a copy of the directory to compress *****/
- snprintf (Path,sizeof (Path),
- "%s/%s",
+ snprintf (Path,sizeof (Path),"%s/%s",
Gbl.FileBrowser.Priv.PathAboveRootFolder,
Gbl.FileBrowser.FilFolLnk.Full);
- snprintf (PathCompression,sizeof (PathCompression),
- "%s/%s",
+ snprintf (PathCompression,sizeof (PathCompression),"%s/%s",
Cfg_PATH_ZIP_PRIVATE,
Gbl.FileBrowser.ZIP.TmpDir); // Example: /var/www/swad/zip/
@@ -401,14 +378,12 @@ static void ZIP_CompressFolderIntoZIP (void)
strcmp (Gbl.FileBrowser.FilFolLnk.Name,".") ? Gbl.FileBrowser.FilFolLnk.Name :
Txt_ROOT_FOLDER_EXTERNAL_NAMES[Gbl.FileBrowser.Type]) < 0)
Lay_NotEnoughMemoryExit ();
- snprintf (PathFileZIP,sizeof (PathFileZIP),
- "%s/%s/%s/%s",
+ snprintf (PathFileZIP,sizeof (PathFileZIP),"%s/%s/%s/%s",
Cfg_PATH_FILE_BROWSER_TMP_PUBLIC,
Gbl.FileBrowser.TmpPubDir.L,
Gbl.FileBrowser.TmpPubDir.R,
FileNameZIP);
- snprintf (StrZip,sizeof (StrZip),
- "nice -n 19 zip -q -5 -r '%s' *",
+ snprintf (StrZip,sizeof (StrZip),"nice -n 19 zip -q -5 -r '%s' *",
PathFileZIP);
Result = system (StrZip);
@@ -427,8 +402,7 @@ static void ZIP_CompressFolderIntoZIP (void)
else
{
/* Create URL pointing to ZIP file */
- snprintf (URLWithSpaces,sizeof (URLWithSpaces),
- "%s/%s/%s/%s",
+ snprintf (URLWithSpaces,sizeof (URLWithSpaces),"%s/%s/%s/%s",
Cfg_URL_FILE_BROWSER_TMP_PUBLIC,
Gbl.FileBrowser.TmpPubDir.L,
Gbl.FileBrowser.TmpPubDir.R,
@@ -495,14 +469,11 @@ static unsigned long long ZIP_CloneDir (const char *Path,const char *PathClone,c
if (strcmp (FileList[NumFile]->d_name,".") &&
strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".."
{
- snprintf (PathFileInTree,sizeof (PathFileInTree),
- "%s/%s",
+ snprintf (PathFileInTree,sizeof (PathFileInTree),"%s/%s",
PathInTree,FileList[NumFile]->d_name);
- snprintf (PathFile,sizeof (PathFile),
- "%s/%s",
+ snprintf (PathFile,sizeof (PathFile),"%s/%s",
Path,FileList[NumFile]->d_name);
- snprintf (PathFileClone,sizeof (PathFileClone),
- "%s/%s",
+ snprintf (PathFileClone,sizeof (PathFileClone),"%s/%s",
PathClone,FileList[NumFile]->d_name);
FileType = Brw_IS_UNKNOWN;